* Re: adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-02 16:46 UTC (permalink / raw)
To: phil; +Cc: sensors, Greg KH, khali, linux-kernel
Hi,
Here is the revised adm1026 driver port for kernel 2.6.10-rc1. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm1 {0-255}
pwm1_auto_pwm_min {0-255}
pwm1_enable {0-2} (off, manual, automatic fan control)
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {-6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) == 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id == 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min=255;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) == 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] =
adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] =
adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] =
adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div == 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
return sprintf(buf,"%d\n",
TEMP_FROM_REG(ADM1026_FAN_ACTIVATION_TEMP_HYST));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG((data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE)));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val == 1) || (val==0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable == 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable == 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val == 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable == 1) && (val == 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm1_auto_pwm_min, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company == ADM1026_COMPANY_ANALOG_DEV
&& verstep == ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company == ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind == 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-02 19:31 UTC (permalink / raw)
To: Justin Thiessen; +Cc: sensors, linux-kernel, Greg KH
Hi justin,
> As discussed in previous messages, control over the pwm output is
> provided via:
>
> pwm1 {0-255}
> pwm1_auto_pwm_min {0-255}
What exactly does this value represent again? (See below too.)
> pwm1_enable {0-2} (off, manual, automatic fan control)
>
> Access to the DAC is provided via:
>
> analog_out {0-2500} (millivolts)
>
> No way is currently provided to turn on DAC-mediated automatic fan
> control. See my previous email in this thread for the reasons why.
On a side note, MBM lists the ADM1026 as being used on only two
motherboard models, one being yours. Considering this and the fact that
nobody ever requested us to port the adm1026 driver to Linux 2.6, I
would conclude that the motherboard you use is possibly the only one
worth supporting. Do not bother with anything that you don't personally
need. We can still add it later on request.
> Control over automatic fan "on" temperatures are provided by:
>
> temp[1-3]_auto_point1_temp {-128000 - 127000}
>
> Hardware-determined hysteresis and range values are revealed in:
>
> temp[1-3]_auto_point1_temp_hyst {-6000}
Hysteresis temperatures have to be absolute temperatures as per
interface standard.
> temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
I'm a bit surprised not to see temp[1-3]_auto_point[1-2]_pwm. Trip
points are supposed to be (temp, pwm) pairs. Doesn't pwm1_auto_pwm_min
above correspond to one or more of these?
> Failsafe critical temperatures at which the fans go to maximum speed
> are controled via:
>
> temp_crit_enable {0-1} (off, on)
> temp[1-3]_crit {-128000 - 127000}
Granted it's not part of the standard yet, but you would have three
files temp[1-3]_crit_enable if we stick to our chip-indenpendent
interface logic. Either make 1 read-write and [2-3] read-only, or make
all read-write and each one changes the three values.
> These values override any values set for the pwm-mediated automatic
> fan control.
Doesn't this mean that you could integrate these in the auto-pwm
interface as point3?
> Thanks to all for the feedback.
You're welcome. Sorry to ask questions about the proposed interface
again, I just want things to be as clean and logical as possible.
Thanks,
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-02 22:17 UTC (permalink / raw)
To: LM Sensors, LKML; +Cc: Greg KH
On Tue, Nov 02, 2004 at 08:31:22PM +0100, Jean Delvare wrote:
> Hi justin,
<snip>
> On a side note, MBM lists the ADM1026 as being used on only two
> motherboard models, one being yours. Considering this and the fact that
> nobody ever requested us to port the adm1026 driver to Linux 2.6, I
> would conclude that the motherboard you use is possibly the only one
> worth supporting. Do not bother with anything that you don't personally
> need. We can still add it later on request.
Ok.
> Hysteresis temperatures have to be absolute temperatures as per
> interface standard.
Ok.
> > temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
>
> I'm a bit surprised not to see temp[1-3]_auto_point[1-2]_pwm. Trip
> points are supposed to be (temp, pwm) pairs. Doesn't pwm1_auto_pwm_min
> above correspond to one or more of these?
Yes. On its way. I think it got lost somewhere in my reading of the
discussion over auto-fan interface proposals.
> > Failsafe critical temperatures at which the fans go to maximum speed
> > are controled via:
> >
> > temp_crit_enable {0-1} (off, on)
> > temp[1-3]_crit {-128000 - 127000}
>
> Granted it's not part of the standard yet, but you would have three
> files temp[1-3]_crit_enable if we stick to our chip-indenpendent
> interface logic. Either make 1 read-write and [2-3] read-only, or make
> all read-write and each one changes the three values.
Any reason not to simply provide 3 sysfs files pointing at the same variable/
register bit? Maintaining separate variables for a single, uncomplicated
value seems rather overkill.
> > These values override any values set for the pwm-mediated automatic
> > fan control.
>
> Doesn't this mean that you could integrate these in the auto-pwm
> interface as point3?
No. It is important for this to remain seperate from the auto-pwm interface.
It can be set to operate when PWM control is set to "manual", providing a
useful fail-safe mechanism, or when PWM control is set to "off" (Although
it should not be needed in the latter case, as in theory the fans are running
at full speed when PWM control is disabled.)
Moreover, integrating it into the *auto_pointN_temp heirarchy would be
ugly, as there is really only one set of values (temp[1-3]_auto_point1_temp)
that can be independently changed by the end-user.
temp[1-3]_auto_point1_temp_hyst and temp[1-3]_auto_point2_temp are fixed in
hardware at positions relative to temp[1-3]_auto_point1_temp. The function
of temp[1-3]_crit essentially overlaps that of temp[13]_auto_point2_temp
when both automatic PWM fan control and critical temperature monitoring
are enabled. Both provide temperatures at which fan speeds are ramped up
to maximum. This means integrating the temp[1-3]_crit function into the
*_auto_point?_temp heirarchy would result in 2 distinct sets of files that
determine when fan speeds are supposed to go to max.
A better way to think of it is that the temp[1-3]_crit files provide a
method for the end-user to set absolute "holy-cow-my-system-is-glowing"
temperatures at which fans MUST ramp up to full speed. It's a fail-safe
that will kick in to try and save the system's bacon in an emergency. As
it operates with or without the PWM automatic fan control, it can be employed
whether or not the end-user wants to muck about with such.
I would agree that it is a bit confusing that there are essentially 2
temperature-motivated mechanisms for forcing fan speeds to full (automatic
PWM fan control, and critical temperature monitoring), but I think that the
utility of providing a critical temperature fail-safe is worth the
minor amount of confusion.
> > Thanks to all for the feedback.
>
> You're welcome. Sorry to ask questions about the proposed interface
> again, I just want things to be as clean and logical as possible.
No problem. Sorry that it's taking so much revision to get the kinks worked
out. This will undoubtedly become less trouble as I get more familiar with
i2c/lm_sensors/kernel issues.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-03 8:01 UTC (permalink / raw)
To: jthiessen, sensors, linux-kernel; +Cc: Greg KH
Hi Justin,
> > Granted it's not part of the standard yet, but you would have three
> > files temp[1-3]_crit_enable if we stick to our chip-indenpendent
> > interface logic. Either make 1 read-write and [2-3] read-only, or make
> > all read-write and each one changes the three values.
>
> Any reason not to simply provide 3 sysfs files pointing at the same
> variable/register bit? Maintaining separate variables for a single,
> uncomplicated value seems rather overkill.
That's pretty much what I was proposing, actually ;) I never meant three
different variables. The discussion was about having all files
read-write or not. I usually have only the first file read-write and
others read-only mirrors thereof, but sometimes people don't like that
arbitrary symmetry breakage and go for read-write mirrors. You choose.
> (...)
> I would agree that it is a bit confusing that there are essentially 2
> temperature-motivated mechanisms for forcing fan speeds to full (automatic
> PWM fan control, and critical temperature monitoring), but I think that the
> utility of providing a critical temperature fail-safe is worth the
> minor amount of confusion.
Agreed.
> No problem. Sorry that it's taking so much revision to get the kinks
> worked out. This will undoubtedly become less trouble as I get more
> familiar with i2c/lm_sensors/kernel issues.
Well, the adm1026 driver is a complex driver which never received testing
and reviewing so far, because it is so rarely found on motherboards.
It's perfectly normal that it takes a couple revisions and discussion
to get it in good shape. Thanks for the good work so far.
--
Jean Delvare
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.X - [RE-REVISED DRIVER]
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-03 16:43 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Ok, let's try this again:
Here is the revised adm1026 driver port for kernel 2.6.10-rc1. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable and simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
#define ADM1026_PWM_MAX 255
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) == 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id == 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min=255;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) == 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] =
adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] =
adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] =
adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div == 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(
ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val == 1) || (val==0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable == 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable == 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
{
return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val == 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable == 1) && (val == 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company == ADM1026_COMPANY_ANALOG_DEV
&& verstep == ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company == ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind == 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm2);
device_create_file(&new_client->dev, &dev_attr_pwm3);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.X - [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-16 18:56 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, sensors, linux-kernel
> Hi,
>
> Ok, let's try this again:
Fine with me. Care to send this again as a patch against 2.6.10-rc2?
This would include updates to drivers/i2c/chips/Makefile and
drivers/i2c/chips/Kconfig.
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-18 18:56 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Ok, let's try this (yet) again:
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
#define ADM1026_PWM_MAX 255
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) == 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id == 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min=255;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) == 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] =
adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] =
adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] =
adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) == 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div == 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(
ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val == 1) || (val==0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable == 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable == 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
{
return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val == 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable == 1) && (val == 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company == ADM1026_COMPANY_ANALOG_DEV
&& verstep == ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company == ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind == 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm2);
device_create_file(&new_client->dev, &dev_attr_pwm3);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-20 9:57 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, sensors, linux-kernel
Hi Justin,
> Ok, let's try this (yet) again:
I'm sorry to insist be we really want this as a patch against
2.6.10-rc2. That's what Greg needs. As said earlier, the patch would
include the new adm1026.c file (obviously) as well as the necessary
changes to Kconfig and Makefile.
Other than that I'm fine with the code itself.
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Arjan van de Ven
-1 siblings, 0 replies; 51+ messages in thread
From: Arjan van de Ven @ 2004-11-20 10:13 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, phil, khali, sensors, linux-kernel
On Thu, 2004-11-18 at 10:56 -0800, Justin Thiessen wrote:
> MODULE_PARM(gpio_input,"1-17i");
new 2.6 drivers should NOT use MODULE_PARM, it's deprecated.
use module_param() instead
> int adm1026_attach_adapter(struct i2c_adapter *adapter)
> {
> if (!(adapter->class & I2C_CLASS_HWMON)) {
> return 0;
> }
no need for extra { }'s in such a case
> static ssize_t show_in(struct device *dev, char *buf, int nr)
> {
> struct adm1026_data *data = adm1026_update_device(dev);
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> }
any chance you could make this use snprintf instead ?
> static ssize_t show_in_max(struct device *dev, char *buf, int nr)
> {
> struct adm1026_data *data = adm1026_update_device(dev);
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
> }
same question
> static ssize_t store_pwm_reg(struct i2c_client *client,
> struct adm1026_data *data, size_t count)
> {
> adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
> up(&data->update_lock);
> return count;
> }
> static ssize_t set_pwm_reg(struct device *dev, const char *buf,
> size_t count)
> {
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> if (data->pwm1.enable == 1) {
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->pwm1.pwm = PWM_TO_REG(val);
> return store_pwm_reg(client, data, count);
> }
this locking construct is rahter awkward; is it possible to refactor the
code such that you can down and up in the same function ?
> static ssize_t store_auto_pwm_min(struct i2c_client *client,
> struct adm1026_data *data, size_t count)
> {
> data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
> PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
> adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
> up(&data->update_lock);
> return count;
> }
> static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
> size_t count)
> {
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
> if (data->pwm1.enable == 2) { /* apply immediately */
> return store_auto_pwm_min(client, data, count);
> } else { /* wait til automatic fan control is enabled to apply */
> up(&data->update_lock);
> return count;
> }
> }
... here the same construct but even more awkward
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Arjan van de Ven
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-20 10:32 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Justin Thiessen, Greg KH, LM Sensors, LKML
Hi Arjan,
> > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > {
> > struct adm1026_data *data = adm1026_update_device(dev);
> > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > }
>
> any chance you could make this use snprintf instead ?
None of the other hardware monitoring clients driver do, nor do I think
they should. What are we trying to improve?
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-22 19:35 UTC (permalink / raw)
To: LM Sensors; +Cc: greg, linux-kernel
On Sat, Nov 20, 2004 at 10:57:40AM +0100, Jean Delvare wrote:
> Hi Justin,
>
> > Ok, let's try this (yet) again:
>
> I'm sorry to insist be we really want this as a patch against
> 2.6.10-rc2. That's what Greg needs. As said earlier, the patch would
> include the new adm1026.c file (obviously) as well as the necessary
> changes to Kconfig and Makefile.
Ack. Sorry for forgetting the Kconfig and Makefile changes.
The driver itself is actually a patch against 2.6.10-rc2.
I'll post the driver once the issues Arjan raised have been resolved.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Arjan van de Ven
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-22 19:43 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: greg, phil, khali, sensors, linux-kernel
On Sat, Nov 20, 2004 at 11:13:56AM +0100, Arjan van de Ven wrote:
> On Thu, 2004-11-18 at 10:56 -0800, Justin Thiessen wrote:
> > MODULE_PARM(gpio_input,"1-17i");
>
> new 2.6 drivers should NOT use MODULE_PARM, it's deprecated.
> use module_param() instead
Ok. You mean module_param_array() in these particular cases, right?
> > int adm1026_attach_adapter(struct i2c_adapter *adapter)
> > {
> > if (!(adapter->class & I2C_CLASS_HWMON)) {
> > return 0;
> > }
>
> no need for extra { }'s in such a case
Of course there's no _need_. But I find the result stylistically easier to
read. Is there any real objection?
> > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > {
> > struct adm1026_data *data = adm1026_update_device(dev);
> > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > }
>
> any chance you could make this use snprintf instead ?
I'll defer to Jean's response...
<snip awkward locking construct>
> this locking construct is rahter awkward; is it possible to refactor the
> code such that you can down and up in the same function ?
Yes, at the cost of some minor code duplication or the introduction of
another variable. Is that preferable? Is holding the lock across function
calls a Bad Idea?
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Arjan van de Ven
-1 siblings, 0 replies; 51+ messages in thread
From: Arjan van de Ven @ 2004-11-22 21:00 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, phil, khali, sensors, linux-kernel
> > this locking construct is rahter awkward; is it possible to refactor the
> > code such that you can down and up in the same function ?
>
> Yes, at the cost of some minor code duplication or the introduction of
> another variable. Is that preferable? Is holding the lock across function
> calls a Bad Idea?
holding lock across function calls isn't, unlocking in another function than you take the lock is.
For one it makes auditing the code a lot harder.
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Arjan van de Ven
@ 2005-05-19 6:25 ` linux-os
-1 siblings, 0 replies; 51+ messages in thread
From: linux-os @ 2004-11-22 21:30 UTC (permalink / raw)
To: Arjan van de Ven
Cc: Justin Thiessen, greg, phil, khali, sensors, linux-kernel
On Mon, 22 Nov 2004, Arjan van de Ven wrote:
>
>>> this locking construct is rahter awkward; is it possible to refactor the
>>> code such that you can down and up in the same function ?
>>
>> Yes, at the cost of some minor code duplication or the introduction of
>> another variable. Is that preferable? Is holding the lock across function
>> calls a Bad Idea?
>
> holding lock across function calls isn't, unlocking in another function
> than you take the lock is.
> For one it makes auditing the code a lot harder.
>
Also, code like:
down(&mylock);
do_something();
if(fail) {
up(&mylock);
return retval;
}
... is prone to errors where a lock never gets released on some
corner cases. It's often better to "goto" a common exit point where
the lock is released.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by John Ashcroft.
98.36% of all statistics are fiction.
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile)
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-23 16:52 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Taking into account Arjan's comments, I have fixed the awkward locking
constructs. I have also switched from using MODULE_PARM() to
module_param_array(). As Jean requested (and as I muttonheadedly ignored)
on the last submission, the diff now includes the patches to
.../drivers/i2c/chips/Makefile
.../drivers/i2c/chips/Kconfig
Finally (and you've all read this before):
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig linux-2.6.10-rc2/drivers/i2c/chips/Kconfig
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Kconfig 2004-11-16 17:09:36.000000000 -0800
@@ -32,6 +32,15 @@ config SENSORS_ADM1025
This driver can also be built as a module. If so, the module
will be called adm1025.
+config SENSORS_ADM1026
+ tristate "Analog Devices ADM1026 and compatibles"
+ depends on I2C && EXPERIMENTAL
+ select I2C_SENSOR
+ help
+ If you say yes here you get support for Analog Devices ADM1026
+ This driver can also be built as a module. If so, the module
+ will be called adm1026.
+
config SENSORS_ADM1031
tristate "Analog Devices ADM1031 and compatibles"
depends on I2C && EXPERIMENTAL
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile linux-2.6.10-rc2/drivers/i2c/chips/Makefile
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Makefile 2004-11-16 17:09:10.000000000 -0800
@@ -9,6 +9,7 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
+obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c 1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c 2004-11-22 13:14:39.000000000 -0800
@@ -0,0 +1,1779 @@
+/*
+ adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
+ monitoring
+ Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
+ Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
+
+ Chip details at:
+
+ <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
+
+ 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 <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c-sensor.h>
+#include <linux/i2c-vid.h>
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
+static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
+
+/* Insmod parameters */
+SENSORS_INSMOD_1(adm1026);
+
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+module_param_array(gpio_input,int,NULL,0);
+MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output,int,NULL,0);
+MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+ "outputs");
+module_param_array(gpio_inverted,int,NULL,0);
+MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+ "inverted");
+module_param_array(gpio_normal,int,NULL,0);
+MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+ "normal/non-inverted");
+module_param_array(gpio_fan,int,NULL,0);
+MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+
+/* Many ADM1026 constants specified below */
+
+/* The ADM1026 registers */
+#define ADM1026_REG_CONFIG1 0x00
+#define CFG1_MONITOR 0x01
+#define CFG1_INT_ENABLE 0x02
+#define CFG1_INT_CLEAR 0x04
+#define CFG1_AIN8_9 0x08
+#define CFG1_THERM_HOT 0x10
+#define CFG1_DAC_AFC 0x20
+#define CFG1_PWM_AFC 0x40
+#define CFG1_RESET 0x80
+#define ADM1026_REG_CONFIG2 0x01
+/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
+#define ADM1026_REG_CONFIG3 0x07
+#define CFG3_GPIO16_ENABLE 0x01
+#define CFG3_CI_CLEAR 0x02
+#define CFG3_VREF_250 0x04
+#define CFG3_GPIO16_DIR 0x40
+#define CFG3_GPIO16_POL 0x80
+#define ADM1026_REG_E2CONFIG 0x13
+#define E2CFG_READ 0x01
+#define E2CFG_WRITE 0x02
+#define E2CFG_ERASE 0x04
+#define E2CFG_ROM 0x08
+#define E2CFG_CLK_EXT 0x80
+
+/* There are 10 general analog inputs and 7 dedicated inputs
+ * They are:
+ * 0 - 9 = AIN0 - AIN9
+ * 10 = Vbat
+ * 11 = 3.3V Standby
+ * 12 = 3.3V Main
+ * 13 = +5V
+ * 14 = Vccp (CPU core voltage)
+ * 15 = +12V
+ * 16 = -12V
+ */
+static u16 ADM1026_REG_IN[] = {
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
+ 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
+ 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
+ };
+static u16 ADM1026_REG_IN_MIN[] = {
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
+ 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
+ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+static u16 ADM1026_REG_IN_MAX[] = {
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
+ 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
+ 0x43, 0x44, 0x45, 0x46, 0x47
+ };
+
+/* Temperatures are:
+ * 0 - Internal
+ * 1 - External 1
+ * 2 - External 2
+ */
+static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
+static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
+static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
+static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
+static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
+static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
+
+#define ADM1026_REG_FAN(nr) (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3 0x02
+#define ADM1026_REG_FAN_DIV_4_7 0x03
+
+#define ADM1026_REG_DAC 0x04
+#define ADM1026_REG_PWM 0x05
+
+#define ADM1026_REG_GPIO_CFG_0_3 0x08
+#define ADM1026_REG_GPIO_CFG_4_7 0x09
+#define ADM1026_REG_GPIO_CFG_8_11 0x0a
+#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+/* CFG_16 in REG_CFG3 */
+#define ADM1026_REG_GPIO_STATUS_0_7 0x24
+#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+/* STATUS_16 in REG_STATUS4 */
+#define ADM1026_REG_GPIO_MASK_0_7 0x1c
+#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+/* MASK_16 in REG_MASK4 */
+
+#define ADM1026_REG_COMPANY 0x16
+#define ADM1026_REG_VERSTEP 0x17
+/* These are the recognized values for the above regs */
+#define ADM1026_COMPANY_ANALOG_DEV 0x41
+#define ADM1026_VERSTEP_GENERIC 0x40
+#define ADM1026_VERSTEP_ADM1026 0x44
+
+#define ADM1026_REG_MASK1 0x18
+#define ADM1026_REG_MASK2 0x19
+#define ADM1026_REG_MASK3 0x1a
+#define ADM1026_REG_MASK4 0x1b
+
+#define ADM1026_REG_STATUS1 0x20
+#define ADM1026_REG_STATUS2 0x21
+#define ADM1026_REG_STATUS3 0x22
+#define ADM1026_REG_STATUS4 0x23
+
+#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX 255
+
+/* 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.
+ */
+
+/* IN are scaled acording to built-in resistors. These are the
+ * voltages corresponding to 3/4 of full scale (192 or 0xc0)
+ * NOTE: The -12V input needs an additional factor to account
+ * for the Vref pullup resistor.
+ * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
+ * = 13875 * 2.50 / 1.875 - 2500
+ * = 16000
+ *
+ * The values in this table are based on Table II, page 15 of the
+ * datasheet.
+ */
+static int adm1026_scaling[] = { /* .001 Volts */
+ 2250, 2250, 2250, 2250, 2250, 2250,
+ 1875, 1875, 1875, 1875, 3000, 3330,
+ 3330, 4995, 2250, 12000, 13875
+ };
+#define NEG12_OFFSET 16000
+#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
+ 0,255))
+#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+
+/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
+ * and we assume a 2 pulse-per-rev fan tach signal
+ * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
+ */
+#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
+ (div)),1,254))
+#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
+ (div)))
+#define DIV_FROM_REG(val) (1<<(val))
+#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+
+/* Temperature is reported in 1 degC increments */
+#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define TEMP_FROM_REG(val) ((val) * 1000)
+#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define OFFSET_FROM_REG(val) ((val) * 1000)
+
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_FROM_REG(val) (val)
+
+#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
+#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
+
+/* Analog output is a voltage, and scaled to millivolts. The datasheet
+ * indicates that the DAC could be used to drive the fans, but in our
+ * example board (Arima HDAMA) it isn't connected to the fans at all.
+ */
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
+#define DAC_FROM_REG(val) (((val)*2500)/255)
+
+/* Typically used with systems using a v9.1 VRM spec ? */
+#define ADM1026_INIT_VRM 91
+
+/* Chip sampling rates
+ *
+ * Some sensors are not updated more frequently than once per second
+ * so it doesn't make sense to read them more often than that.
+ * We cache the results and return the saved data if the driver
+ * is called again before a second has elapsed.
+ *
+ * Also, there is significant configuration data for this chip
+ * So, we keep the config data up to date in the cache
+ * when it is written and only sample it once every 5 *minutes*
+ */
+#define ADM1026_DATA_INTERVAL (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
+
+/* We allow for multiple chips in a single system.
+ *
+ * For each registered ADM1026, we need to keep state information
+ * at client->data. The adm1026_data structure is dynamically
+ * allocated, when a new client structure is allocated. */
+
+struct pwm_data {
+ u8 pwm;
+ u8 enable;
+ u8 auto_pwm_min;
+};
+
+struct adm1026_data {
+ struct i2c_client client;
+ struct semaphore lock;
+ enum chips type;
+
+ struct semaphore update_lock;
+ int valid; /* !=0 if following fields are valid */
+ unsigned long last_reading; /* In jiffies */
+ unsigned long last_config; /* In jiffies */
+
+ u8 in[17]; /* Register value */
+ u8 in_max[17]; /* Register value */
+ u8 in_min[17]; /* Register value */
+ s8 temp[3]; /* Register value */
+ s8 temp_min[3]; /* Register value */
+ s8 temp_max[3]; /* Register value */
+ s8 temp_tmin[3]; /* Register value */
+ s8 temp_crit[3]; /* Register value */
+ s8 temp_offset[3]; /* Register value */
+ u8 fan[8]; /* Register value */
+ u8 fan_min[8]; /* Register value */
+ u8 fan_div[8]; /* Decoded value */
+ struct pwm_data pwm1; /* Pwm control values */
+ int vid; /* Decoded value */
+ u8 vrm; /* VRM version */
+ u8 analog_out; /* Register value (DAC) */
+ long alarms; /* Register encoding, combined */
+ long alarm_mask; /* Register encoding, combined */
+ long gpio; /* Register encoding, combined */
+ long gpio_mask; /* Register encoding, combined */
+ u8 gpio_config[17]; /* Decoded value */
+ u8 config1; /* Register value */
+ u8 config2; /* Register value */
+ u8 config3; /* Register value */
+};
+
+static int adm1026_attach_adapter(struct i2c_adapter *adapter);
+static int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind);
+static int adm1026_detach_client(struct i2c_client *client);
+static int adm1026_read_value(struct i2c_client *client, u8 register);
+static int adm1026_write_value(struct i2c_client *client, u8 register,
+ int value);
+static void adm1026_print_gpio(struct i2c_client *client);
+static void adm1026_fixup_gpio(struct i2c_client *client);
+static struct adm1026_data *adm1026_update_device(struct device *dev);
+static void adm1026_init_client(struct i2c_client *client);
+
+
+static struct i2c_driver adm1026_driver = {
+ .owner = THIS_MODULE,
+ .name = "adm1026",
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = adm1026_attach_adapter,
+ .detach_client = adm1026_detach_client,
+};
+
+static int adm1026_id;
+
+int adm1026_attach_adapter(struct i2c_adapter *adapter)
+{
+ if (!(adapter->class & I2C_CLASS_HWMON)) {
+ return 0;
+ }
+ return i2c_detect(adapter, &addr_data, adm1026_detect);
+}
+
+int adm1026_detach_client(struct i2c_client *client)
+{
+ i2c_detach_client(client);
+ kfree(client);
+ return 0;
+}
+
+int adm1026_read_value(struct i2c_client *client, u8 reg)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_read_byte_data(client, reg) & 0xff;
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_write_byte_data(client, reg, value);
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+void adm1026_init_client(struct i2c_client *client)
+{
+ int value, i;
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
+ /* Read chip config */
+ data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
+
+ /* Inform user of chip config */
+ dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
+ client->id, data->config1);
+ if ((data->config1 & CFG1_MONITOR) == 0) {
+ dev_dbg(&client->dev, "(%d): Monitoring not currently "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_INT_ENABLE) {
+ dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_AIN8_9) {
+ dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
+ "temp3 disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
+ "in9 disabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_THERM_HOT) {
+ dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
+ "and temp limits enabled.\n", client->id);
+ }
+
+ value = data->config3;
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
+ "pin disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): THERM pin enabled. "
+ "GPIO16 disabled.\n", client->id);
+ }
+ if (data->config3 & CFG3_VREF_250) {
+ dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
+ client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
+ client->id);
+ }
+ /* Read and pick apart the existing GPIO configuration */
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) == 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ /* ... and then print it */
+ adm1026_print_gpio(client);
+
+ /* If the user asks us to reprogram the GPIO config, then
+ * do it now. But only if this is the first ADM1026.
+ */
+ if (client->id == 0
+ && (gpio_input[0] != -1 || gpio_output[0] != -1
+ || gpio_inverted[0] != -1 || gpio_normal[0] != -1
+ || gpio_fan[0] != -1)) {
+ adm1026_fixup_gpio(client);
+ }
+
+ /* WE INTENTIONALLY make no changes to the limits,
+ * offsets, pwms, fans and zones. If they were
+ * configured, we don't want to mess with them.
+ * If they weren't, the default is 100% PWM, no
+ * control and will suffice until 'sensors -s'
+ * can be run by the user. We DO set the default
+ * value for pwm1.auto_pwm_min to its maximum
+ * so that enabling automatic pwm fan control
+ * without first setting a value for pwm1.auto_pwm_min
+ * will not result in potentially dangerous fan speed decrease.
+ */
+ data->pwm1.auto_pwm_min=255;
+ /* Start monitoring */
+ value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ /* Set MONITOR, clear interrupt acknowledge and s/w reset */
+ value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
+ dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
+ client->id, value);
+ data->config1 = value;
+ adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
+}
+
+void adm1026_print_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+
+ dev_dbg(&client->dev, "(%d): GPIO config is:",
+ client->id);
+ for (i = 0;i <= 7;++i) {
+ if (data->config2 & (1 << i)) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ } else {
+ dev_dbg(&client->dev, "\t(%d): FAN%d\n",
+ client->id, i);
+ }
+ }
+ for (i = 8;i <= 15;++i) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ }
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
+ data->gpio_config[16] & 0x02 ? "" : "!",
+ data->gpio_config[16] & 0x01 ? "OUT" : "IN");
+ } else {
+ /* GPIO16 is THERM */
+ dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
+ }
+}
+
+void adm1026_fixup_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ int value;
+
+ /* Make the changes requested. */
+ /* We may need to unlock/stop monitoring or soft-reset the
+ * chip before we can make changes. This hasn't been
+ * tested much. FIXME
+ */
+
+ /* Make outputs */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
+ data->gpio_config[gpio_output[i]] |= 0x01;
+ }
+ /* if GPIO0-7 is output, it isn't a FAN tach */
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
+ data->config2 |= 1 << gpio_output[i];
+ }
+ }
+
+ /* Input overrides output */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
+ data->gpio_config[gpio_input[i]] &= ~ 0x01;
+ }
+ /* if GPIO0-7 is input, it isn't a FAN tach */
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
+ data->config2 |= 1 << gpio_input[i];
+ }
+ }
+
+ /* Inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
+ data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
+ }
+ }
+
+ /* Normal overrides inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
+ data->gpio_config[gpio_normal[i]] |= 0x02;
+ }
+ }
+
+ /* Fan overrides input and output */
+ for (i = 0;i <= 7;++i) {
+ if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
+ data->config2 &= ~(1 << gpio_fan[i]);
+ }
+ }
+
+ /* Write new configs to registers */
+ adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
+ data->config3 = (data->config3 & 0x3f)
+ | ((data->gpio_config[16] & 0x03) << 6);
+ adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
+ for (i = 15, value = 0;i >= 0;--i) {
+ value <<= 2;
+ value |= data->gpio_config[i] & 0x03;
+ if ((i & 0x03) == 0) {
+ adm1026_write_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4,
+ value);
+ value = 0;
+ }
+ }
+
+ /* Print the new config */
+ adm1026_print_gpio(client);
+}
+
+
+static struct adm1026_data *adm1026_update_device(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ long value, alarms, gpio;
+
+ down(&data->update_lock);
+ if (!data->valid
+ || (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
+ /* Things that change quickly */
+ dev_dbg(&client->dev,"(%d): Reading sensor values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in[i] =
+ adm1026_read_value(client, ADM1026_REG_IN[i]);
+ }
+
+ for (i = 0;i <= 7;++i) {
+ data->fan[i] =
+ adm1026_read_value(client, ADM1026_REG_FAN(i));
+ }
+
+ for (i = 0;i <= 2;++i) {
+ /* NOTE: temp[] is s8 and we assume 2's complement
+ * "conversion" in the assignment */
+ data->temp[i] =
+ adm1026_read_value(client, ADM1026_REG_TEMP[i]);
+ }
+
+ data->pwm1.pwm = adm1026_read_value(client,
+ ADM1026_REG_PWM);
+ data->analog_out = adm1026_read_value(client,
+ ADM1026_REG_DAC);
+ /* GPIO16 is MSbit of alarms, move it to gpio */
+ alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms &= 0x7f;
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
+ data->alarms = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_0_7);
+ data->gpio = gpio;
+
+ data->last_reading = jiffies;
+ }; /* last_reading */
+
+ if (!data->valid || (jiffies - data->last_config >
+ ADM1026_CONFIG_INTERVAL)) {
+ /* Things that don't change often */
+ dev_dbg(&client->dev, "(%d): Reading config values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in_min[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MIN[i]);
+ data->in_max[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MAX[i]);
+ }
+
+ value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
+ | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
+ << 8);
+ for (i = 0;i <= 7;++i) {
+ data->fan_min[i] = adm1026_read_value(client,
+ ADM1026_REG_FAN_MIN(i));
+ data->fan_div[i] = DIV_FROM_REG(value & 0x03);
+ value >>= 2;
+ }
+
+ for (i = 0; i <= 2; ++i) {
+ /* NOTE: temp_xxx[] are s8 and we assume 2's
+ * complement "conversion" in the assignment
+ */
+ data->temp_min[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MIN[i]);
+ data->temp_max[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MAX[i]);
+ data->temp_tmin[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_TMIN[i]);
+ data->temp_crit[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_THERM[i]);
+ data->temp_offset[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_OFFSET[i]);
+ }
+
+ /* Read the STATUS/alarm masks */
+ alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms = (alarms & 0x7f) << 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
+ data->alarm_mask = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_MASK_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
+ data->gpio_mask = gpio;
+
+ /* Read various values from CONFIG1 */
+ data->config1 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG1);
+ if (data->config1 & CFG1_PWM_AFC) {
+ data->pwm1.enable = 2;
+ data->pwm1.auto_pwm_min =
+ PWM_MIN_FROM_REG(data->pwm1.pwm);
+ }
+ /* Read the GPIO config */
+ data->config2 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG3);
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) == 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+
+ data->last_config = jiffies;
+ }; /* last_config */
+
+ dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
+ client->id);
+ data->vid = (data->gpio >> 11) & 0x1f;
+ data->valid = 1;
+ up(&data->update_lock);
+ return data;
+}
+
+static ssize_t show_in(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+}
+static ssize_t show_in_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+}
+static ssize_t set_in_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+}
+static ssize_t set_in_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define in_reg(offset) \
+static ssize_t show_in##offset (struct device *dev, char *buf) \
+{ \
+ return show_in(dev, buf, offset); \
+} \
+static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_in_min(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_min(dev, buf, count, offset); \
+} \
+static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_in_max(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_max(dev, buf, count, offset); \
+} \
+static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
+static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
+ show_in##offset##_min, set_in##offset##_min); \
+static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
+ show_in##offset##_max, set_in##offset##_max);
+
+
+in_reg(0);
+in_reg(1);
+in_reg(2);
+in_reg(3);
+in_reg(4);
+in_reg(5);
+in_reg(6);
+in_reg(7);
+in_reg(8);
+in_reg(9);
+in_reg(10);
+in_reg(11);
+in_reg(12);
+in_reg(13);
+in_reg(14);
+in_reg(15);
+
+static ssize_t show_in16(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+ NEG12_OFFSET);
+}
+static ssize_t show_in16_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in16_max(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
+static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
+static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
+
+
+
+
+/* Now add fan read/write functions */
+
+static ssize_t show_fan(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+ data->fan_div[nr]));
+}
+static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+ data->fan_div[nr]));
+}
+static ssize_t set_fan_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
+ data->fan_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset(offset) \
+static ssize_t show_fan_##offset (struct device *dev, char *buf) \
+{ \
+ return show_fan(dev, buf, offset - 1); \
+} \
+static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_fan_min(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_min(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
+static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_min, set_fan_##offset##_min);
+
+fan_offset(1);
+fan_offset(2);
+fan_offset(3);
+fan_offset(4);
+fan_offset(5);
+fan_offset(6);
+fan_offset(7);
+fan_offset(8);
+
+/* Adjust fan_min to account for new fan divisor */
+void fixup_fan_min(struct device *dev, int fan, int old_div)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int new_min;
+ int new_div = data->fan_div[fan];
+
+ /* 0 and 0xff are special. Don't adjust them */
+ if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
+ return;
+ }
+
+ new_min = data->fan_min[fan] * old_div / new_div;
+ new_min = SENSORS_LIMIT(new_min, 1, 254);
+ data->fan_min[fan] = new_min;
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
+}
+
+/* Now add fan_div read/write functions */
+static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->fan_div[nr]);
+}
+static ssize_t set_fan_div(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val,orig_div,new_div,shift;
+
+ val = simple_strtol(buf, NULL, 10);
+ new_div = DIV_TO_REG(val);
+ if (new_div == 0) {
+ return -EINVAL;
+ }
+ down(&data->update_lock);
+ orig_div = data->fan_div[nr];
+ data->fan_div[nr] = DIV_FROM_REG(new_div);
+
+ if (nr < 4) { /* 0 <= nr < 4 */
+ shift = 2 * nr;
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
+ (new_div << shift)));
+ } else { /* 3 < nr < 8 */
+ shift = 2 * (nr - 4);
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
+ (new_div << shift)));
+ }
+
+ if (data->fan_div[nr] != orig_div) {
+ fixup_fan_min(dev,nr,orig_div);
+ }
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset_div(offset) \
+static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
+{ \
+ return show_fan_div(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_div (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_div(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_div, set_fan_##offset##_div);
+
+fan_offset_div(1);
+fan_offset_div(2);
+fan_offset_div(3);
+fan_offset_div(4);
+fan_offset_div(5);
+fan_offset_div(6);
+fan_offset_div(7);
+fan_offset_div(8);
+
+/* Temps */
+static ssize_t show_temp(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+}
+static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+}
+static ssize_t set_temp_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_min[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
+ data->temp_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+}
+static ssize_t set_temp_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_max[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
+ data->temp_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+#define temp_reg(offset) \
+static ssize_t show_temp_##offset (struct device *dev, char *buf) \
+{ \
+ return show_temp(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_temp_min(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_temp_max(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_min(dev, buf, count, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_max(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
+static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_min, set_temp_##offset##_min); \
+static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_max, set_temp_##offset##_max);
+
+
+temp_reg(1);
+temp_reg(2);
+temp_reg(3);
+
+static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+}
+static ssize_t set_temp_offset(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_offset[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
+ data->temp_offset[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_offset_reg(offset) \
+static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
+{ \
+ return show_temp_offset(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_offset (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_offset(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_offset, set_temp_##offset##_offset);
+
+temp_offset_reg(1);
+temp_offset_reg(2);
+temp_offset_reg(3);
+
+static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(
+ ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
+}
+static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+ ADM1026_FAN_CONTROL_TEMP_RANGE));
+}
+static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+}
+static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_tmin[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
+ data->temp_tmin[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_auto_point(offset) \
+static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point1_temp(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
+ *dev, char *buf) \
+{ \
+ return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point2_temp(dev, buf, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
+ show_temp##offset##_auto_point1_temp, \
+ set_temp##offset##_auto_point1_temp); \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
+ show_temp##offset##_auto_point1_temp_hyst, NULL); \
+static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
+ show_temp##offset##_auto_point2_temp, NULL);
+
+temp_auto_point(1);
+temp_auto_point(2);
+temp_auto_point(3);
+
+static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+}
+static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val == 1) || (val==0)) {
+ down(&data->update_lock);
+ data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+
+static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+}
+static ssize_t set_temp_crit(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_crit[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
+ data->temp_crit[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_crit_reg(offset) \
+static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
+{ \
+ return show_temp_crit(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_crit (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_crit(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_crit, set_temp_##offset##_crit);
+
+temp_crit_reg(1);
+temp_crit_reg(2);
+temp_crit_reg(3);
+
+static ssize_t show_analog_out_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+}
+static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->analog_out = DAC_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
+ set_analog_out_reg);
+
+static ssize_t show_vid_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+}
+
+static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
+
+static ssize_t show_vrm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->vrm);
+}
+static ssize_t store_vrm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ data->vrm = simple_strtol(buf, NULL, 10);
+ return count;
+}
+
+static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
+
+static ssize_t show_alarms_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf, "%ld\n", (long) (data->alarms));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
+
+static ssize_t show_alarm_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->alarm_mask);
+}
+static ssize_t set_alarm_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ unsigned long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->alarm_mask = val & 0x7fffffff;
+ mask = data->alarm_mask
+ | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
+ adm1026_write_value(client, ADM1026_REG_MASK1,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK2,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK3,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK4,
+ mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
+ set_alarm_mask);
+
+
+static ssize_t show_gpio(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio);
+}
+static ssize_t set_gpio(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long gpio;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio = val & 0x1ffff;
+ gpio = data->gpio;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+ gpio >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+ gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
+
+
+static ssize_t show_gpio_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio_mask);
+}
+static ssize_t set_gpio_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio_mask = val & 0x1ffff;
+ mask = data->gpio_mask;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+ mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
+
+static ssize_t show_pwm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
+}
+static ssize_t set_pwm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ if (data->pwm1.enable == 1) {
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.pwm = PWM_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ up(&data->update_lock);
+ }
+ return count;
+}
+static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
+}
+static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
+ if (data->pwm1.enable == 2) { /* apply immediately */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
+{
+ return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
+}
+static ssize_t show_pwm_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.enable);
+}
+static ssize_t set_pwm_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ int old_enable;
+
+ if ((val >= 0) && (val < 3)) {
+ down(&data->update_lock);
+ old_enable = data->pwm1.enable;
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.enable = val;
+ data->config1 = (data->config1 & ~CFG1_PWM_AFC)
+ | ((val == 2) ? CFG1_PWM_AFC : 0);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ } else if (!((old_enable == 1) && (val == 1))) {
+ /* set pwm to safe value */
+ data->pwm1.pwm = 255;
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+/* enable PWM fan control */
+static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+
+static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+
+int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind)
+{
+ int company, verstep;
+ struct i2c_client *new_client;
+ struct adm1026_data *data;
+ int err = 0;
+ const char *type_name = "";
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+ /* We need to be able to do byte I/O */
+ goto exit;
+ };
+
+ /* 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 adm1026_{read,write}_value. */
+
+ if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ memset(data, 0, sizeof(struct adm1026_data));
+
+ new_client = &data->client;
+ i2c_set_clientdata(new_client, data);
+ new_client->addr = address;
+ new_client->adapter = adapter;
+ new_client->driver = &adm1026_driver;
+ new_client->flags = 0;
+
+ /* Now, we do the remaining detection. */
+
+ company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
+ verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
+
+ dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
+ " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
+ i2c_adapter_id(new_client->adapter), new_client->addr,
+ company, verstep);
+
+ /* If auto-detecting, Determine the chip type. */
+ if (kind <= 0) {
+ dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
+ "...\n", i2c_adapter_id(adapter), address);
+ if (company == ADM1026_COMPANY_ANALOG_DEV
+ && verstep == ADM1026_VERSTEP_ADM1026) {
+ kind = adm1026;
+ } else if (company == ADM1026_COMPANY_ANALOG_DEV
+ && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Unrecognized stepping "
+ "0x%02x. Defaulting to ADM1026.\n", verstep);
+ kind = adm1026;
+ } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Found version/stepping "
+ "0x%02x. Assuming generic ADM1026.\n",
+ verstep);
+ kind = any_chip;
+ } else {
+ dev_dbg(&new_client->dev, ": Autodetection "
+ "failed\n");
+ /* Not an ADM1026 ... */
+ if (kind == 0) { /* User used force=x,y */
+ dev_err(&adapter->dev, "Generic ADM1026 not "
+ "found at %d,0x%02x. Try "
+ "force_adm1026.\n",
+ i2c_adapter_id(adapter), address);
+ }
+ err = 0;
+ goto exitfree;
+ }
+ }
+
+ /* Fill in the chip specific driver values */
+ switch (kind) {
+ case any_chip :
+ type_name = "adm1026";
+ break;
+ case adm1026 :
+ type_name = "adm1026";
+ break;
+ default :
+ dev_err(&adapter->dev, ": Internal error, invalid "
+ "kind (%d)!", kind);
+ err = -EFAULT;
+ goto exitfree;
+ }
+ strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
+
+ /* Fill in the remaining client fields */
+ new_client->id = adm1026_id++;
+ data->type = kind;
+ data->valid = 0;
+ init_MUTEX(&data->update_lock);
+
+ dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
+ new_client->id, new_client->id, new_client->name,
+ i2c_adapter_id(new_client->adapter),
+ new_client->addr);
+
+ /* Tell the I2C layer a new client has arrived */
+ if ((err = i2c_attach_client(new_client)))
+ goto exitfree;
+
+ /* Set the VRM version */
+ data->vrm = i2c_which_vrm();
+
+ /* Initialize the ADM1026 chip */
+ adm1026_init_client(new_client);
+
+ /* Register sysfs hooks */
+ device_create_file(&new_client->dev, &dev_attr_in0_input);
+ device_create_file(&new_client->dev, &dev_attr_in0_max);
+ device_create_file(&new_client->dev, &dev_attr_in0_min);
+ device_create_file(&new_client->dev, &dev_attr_in1_input);
+ device_create_file(&new_client->dev, &dev_attr_in1_max);
+ device_create_file(&new_client->dev, &dev_attr_in1_min);
+ device_create_file(&new_client->dev, &dev_attr_in2_input);
+ device_create_file(&new_client->dev, &dev_attr_in2_max);
+ device_create_file(&new_client->dev, &dev_attr_in2_min);
+ device_create_file(&new_client->dev, &dev_attr_in3_input);
+ device_create_file(&new_client->dev, &dev_attr_in3_max);
+ device_create_file(&new_client->dev, &dev_attr_in3_min);
+ device_create_file(&new_client->dev, &dev_attr_in4_input);
+ device_create_file(&new_client->dev, &dev_attr_in4_max);
+ device_create_file(&new_client->dev, &dev_attr_in4_min);
+ device_create_file(&new_client->dev, &dev_attr_in5_input);
+ device_create_file(&new_client->dev, &dev_attr_in5_max);
+ device_create_file(&new_client->dev, &dev_attr_in5_min);
+ device_create_file(&new_client->dev, &dev_attr_in6_input);
+ device_create_file(&new_client->dev, &dev_attr_in6_max);
+ device_create_file(&new_client->dev, &dev_attr_in6_min);
+ device_create_file(&new_client->dev, &dev_attr_in7_input);
+ device_create_file(&new_client->dev, &dev_attr_in7_max);
+ device_create_file(&new_client->dev, &dev_attr_in7_min);
+ device_create_file(&new_client->dev, &dev_attr_in8_input);
+ device_create_file(&new_client->dev, &dev_attr_in8_max);
+ device_create_file(&new_client->dev, &dev_attr_in8_min);
+ device_create_file(&new_client->dev, &dev_attr_in9_input);
+ device_create_file(&new_client->dev, &dev_attr_in9_max);
+ device_create_file(&new_client->dev, &dev_attr_in9_min);
+ device_create_file(&new_client->dev, &dev_attr_in10_input);
+ device_create_file(&new_client->dev, &dev_attr_in10_max);
+ device_create_file(&new_client->dev, &dev_attr_in10_min);
+ device_create_file(&new_client->dev, &dev_attr_in11_input);
+ device_create_file(&new_client->dev, &dev_attr_in11_max);
+ device_create_file(&new_client->dev, &dev_attr_in11_min);
+ device_create_file(&new_client->dev, &dev_attr_in12_input);
+ device_create_file(&new_client->dev, &dev_attr_in12_max);
+ device_create_file(&new_client->dev, &dev_attr_in12_min);
+ device_create_file(&new_client->dev, &dev_attr_in13_input);
+ device_create_file(&new_client->dev, &dev_attr_in13_max);
+ device_create_file(&new_client->dev, &dev_attr_in13_min);
+ device_create_file(&new_client->dev, &dev_attr_in14_input);
+ device_create_file(&new_client->dev, &dev_attr_in14_max);
+ device_create_file(&new_client->dev, &dev_attr_in14_min);
+ device_create_file(&new_client->dev, &dev_attr_in15_input);
+ device_create_file(&new_client->dev, &dev_attr_in15_max);
+ device_create_file(&new_client->dev, &dev_attr_in15_min);
+ device_create_file(&new_client->dev, &dev_attr_in16_input);
+ device_create_file(&new_client->dev, &dev_attr_in16_max);
+ device_create_file(&new_client->dev, &dev_attr_in16_min);
+ device_create_file(&new_client->dev, &dev_attr_fan1_input);
+ device_create_file(&new_client->dev, &dev_attr_fan1_div);
+ device_create_file(&new_client->dev, &dev_attr_fan1_min);
+ device_create_file(&new_client->dev, &dev_attr_fan2_input);
+ device_create_file(&new_client->dev, &dev_attr_fan2_div);
+ device_create_file(&new_client->dev, &dev_attr_fan2_min);
+ device_create_file(&new_client->dev, &dev_attr_fan3_input);
+ device_create_file(&new_client->dev, &dev_attr_fan3_div);
+ device_create_file(&new_client->dev, &dev_attr_fan3_min);
+ device_create_file(&new_client->dev, &dev_attr_fan4_input);
+ device_create_file(&new_client->dev, &dev_attr_fan4_div);
+ device_create_file(&new_client->dev, &dev_attr_fan4_min);
+ device_create_file(&new_client->dev, &dev_attr_fan5_input);
+ device_create_file(&new_client->dev, &dev_attr_fan5_div);
+ device_create_file(&new_client->dev, &dev_attr_fan5_min);
+ device_create_file(&new_client->dev, &dev_attr_fan6_input);
+ device_create_file(&new_client->dev, &dev_attr_fan6_div);
+ device_create_file(&new_client->dev, &dev_attr_fan6_min);
+ device_create_file(&new_client->dev, &dev_attr_fan7_input);
+ device_create_file(&new_client->dev, &dev_attr_fan7_div);
+ device_create_file(&new_client->dev, &dev_attr_fan7_min);
+ device_create_file(&new_client->dev, &dev_attr_fan8_input);
+ device_create_file(&new_client->dev, &dev_attr_fan8_div);
+ device_create_file(&new_client->dev, &dev_attr_fan8_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_input);
+ device_create_file(&new_client->dev, &dev_attr_temp1_max);
+ device_create_file(&new_client->dev, &dev_attr_temp1_min);
+ device_create_file(&new_client->dev, &dev_attr_temp2_input);
+ device_create_file(&new_client->dev, &dev_attr_temp2_max);
+ device_create_file(&new_client->dev, &dev_attr_temp2_min);
+ device_create_file(&new_client->dev, &dev_attr_temp3_input);
+ device_create_file(&new_client->dev, &dev_attr_temp3_max);
+ device_create_file(&new_client->dev, &dev_attr_temp3_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp2_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp3_offset);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point2_temp);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_vid);
+ device_create_file(&new_client->dev, &dev_attr_vrm);
+ device_create_file(&new_client->dev, &dev_attr_alarms);
+ device_create_file(&new_client->dev, &dev_attr_alarm_mask);
+ device_create_file(&new_client->dev, &dev_attr_gpio);
+ device_create_file(&new_client->dev, &dev_attr_gpio_mask);
+ device_create_file(&new_client->dev, &dev_attr_pwm1);
+ device_create_file(&new_client->dev, &dev_attr_pwm2);
+ device_create_file(&new_client->dev, &dev_attr_pwm3);
+ device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_analog_out);
+ return 0;
+
+ /* Error out and cleanup code */
+exitfree:
+ kfree(new_client);
+exit:
+ return err;
+}
+static int __init sm_adm1026_init(void)
+{
+ return i2c_add_driver(&adm1026_driver);
+}
+
+static void __exit sm_adm1026_exit(void)
+{
+ i2c_del_driver(&adm1026_driver);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
+ "Justin Thiessen <jthiessen@penguincomputing.com>");
+MODULE_DESCRIPTION("ADM1026 driver");
+
+module_init(sm_adm1026_init);
+module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile)
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-23 17:50 UTC (permalink / raw)
To: Justin Thiessen; +Cc: sensors, linux-kernel, Greg KH
> Taking into account Arjan's comments, I have fixed the awkward
> locking constructs. I have also switched from using MODULE_PARM()
> to module_param_array(). As Jean requested (and as I muttonheadedly
> ignored) on the last submission, the diff now includes the patches to
>
> .../drivers/i2c/chips/Makefile
> .../drivers/i2c/chips/Kconfig
Great, looks good enough to me. I'd like to see this patch applied to
the kernel. Any further change can be done through incremental patches,
which are so easier to review.
Thanks Justin for the good work :)
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
-1 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2004-11-23 17:58 UTC (permalink / raw)
To: Justin Thiessen, Arjan van de Ven; +Cc: LM Sensors, LKML
> > > int adm1026_attach_adapter(struct i2c_adapter *adapter)
> > > {
> > > if (!(adapter->class & I2C_CLASS_HWMON)) {
> > > return 0;
> > > }
> >
> > no need for extra { }'s in such a case
>
> Of course there's no _need_. But I find the result stylistically
> easier to read. Is there any real objection?
There isn't as far as I can tell. The CodingStyle document doesn't
mention a preference for any form or the other, nor does Greg's talk
about coding style. This means that you are free. If anyone wants it the
other way and is brave enough, he/she can submit an incremental patch
for Greg to consider and see how Greg receives it ;)
> > > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > > {
> > > struct adm1026_data *data = adm1026_update_device(dev);
> > > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > > }
> >
> > any chance you could make this use snprintf instead ?
>
> I'll defer to Jean's response...
And I'll defer to Arjan's myself. As said in another post, no other i2c
client driver does use snprintf. If there is no good reason for them to
do (and actually I don't see any) let's stick to sprintf for everyone.
If there is, then we shall fix all drivers, not only adm1026.
Thanks,
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile)
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Justin Thiessen
@ 2005-05-19 6:25 ` Greg KH
-1 siblings, 0 replies; 51+ messages in thread
From: Greg KH @ 2004-11-24 21:36 UTC (permalink / raw)
To: Justin Thiessen; +Cc: phil, khali, sensors, linux-kernel
Hm, this looks like a bug:
> +static ssize_t set_pwm_enable(struct device *dev, const char *buf,
> + size_t count)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct adm1026_data *data = i2c_get_clientdata(client);
> + int val;
> + int old_enable;
> +
> + if ((val >= 0) && (val < 3)) {
You are using val before assigning it anything. The compiler warns you
about this issue.
Care to fix this up and resend the whole patch?
Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
used :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) [fixed]
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes Justin Thiessen
@ 2005-05-19 6:25 ` Greg KH
-1 siblings, 0 replies; 51+ messages in thread
From: Greg KH @ 2004-11-24 22:35 UTC (permalink / raw)
To: Justin Thiessen; +Cc: phil, khali, sensors, linux-kernel
On Wed, Nov 24, 2004 at 03:10:17PM -0800, Justin Thiessen wrote:
> On Wed, Nov 24, 2004 at 01:36:00PM -0800, Greg KH wrote:
> > Hm, this looks like a bug:
>
> <snip egregious stupidity>
>
> > Care to fix this up and resend the whole patch?
>
> Affirmative.
>
> > Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
> > used :)
>
> See below:
Applied, thanks.
Oh, I did make one change:
> +/* Adjust fan_min to account for new fan divisor */
> +void fixup_fan_min(struct device *dev, int fan, int old_div)
This should be static.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) [fixed]
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Greg KH
@ 2005-05-19 6:25 ` Justin Thiessen
-1 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2004-11-24 23:10 UTC (permalink / raw)
To: Greg KH; +Cc: phil, khali, sensors, linux-kernel
On Wed, Nov 24, 2004 at 01:36:00PM -0800, Greg KH wrote:
> Hm, this looks like a bug:
<snip egregious stupidity>
> Care to fix this up and resend the whole patch?
Affirmative.
> Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
> used :)
See below:
--------------
Hi,
Taking into account Arjan's comments, I have fixed the awkward locking
constructs. I have also switched from using MODULE_PARM() to
module_param_array(). As Jean requested (and as I muttonheadedly ignored)
on the last submission, the diff now includes the patches to
../drivers/i2c/chips/Makefile
../drivers/i2c/chips/Kconfig
Finally (and you've all read this before):
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Finally, the val-comparison-before-assignment bug has been corrected.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed-off-by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig linux-2.6.10-rc2/drivers/i2c/chips/Kconfig
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Kconfig 2004-11-16 17:09:36.000000000 -0800
@@ -32,6 +32,15 @@ config SENSORS_ADM1025
This driver can also be built as a module. If so, the module
will be called adm1025.
+config SENSORS_ADM1026
+ tristate "Analog Devices ADM1026 and compatibles"
+ depends on I2C && EXPERIMENTAL
+ select I2C_SENSOR
+ help
+ If you say yes here you get support for Analog Devices ADM1026
+ This driver can also be built as a module. If so, the module
+ will be called adm1026.
+
config SENSORS_ADM1031
tristate "Analog Devices ADM1031 and compatibles"
depends on I2C && EXPERIMENTAL
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile linux-2.6.10-rc2/drivers/i2c/chips/Makefile
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Makefile 2004-11-16 17:09:10.000000000 -0800
@@ -9,6 +9,7 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
+obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c 1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c 2004-11-22 13:14:39.000000000 -0800
@@ -0,0 +1,1779 @@
+/*
+ adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
+ monitoring
+ Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
+ Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
+
+ Chip details at:
+
+ <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
+
+ 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 <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c-sensor.h>
+#include <linux/i2c-vid.h>
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
+static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
+
+/* Insmod parameters */
+SENSORS_INSMOD_1(adm1026);
+
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+module_param_array(gpio_input,int,NULL,0);
+MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output,int,NULL,0);
+MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+ "outputs");
+module_param_array(gpio_inverted,int,NULL,0);
+MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+ "inverted");
+module_param_array(gpio_normal,int,NULL,0);
+MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+ "normal/non-inverted");
+module_param_array(gpio_fan,int,NULL,0);
+MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+
+/* Many ADM1026 constants specified below */
+
+/* The ADM1026 registers */
+#define ADM1026_REG_CONFIG1 0x00
+#define CFG1_MONITOR 0x01
+#define CFG1_INT_ENABLE 0x02
+#define CFG1_INT_CLEAR 0x04
+#define CFG1_AIN8_9 0x08
+#define CFG1_THERM_HOT 0x10
+#define CFG1_DAC_AFC 0x20
+#define CFG1_PWM_AFC 0x40
+#define CFG1_RESET 0x80
+#define ADM1026_REG_CONFIG2 0x01
+/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
+#define ADM1026_REG_CONFIG3 0x07
+#define CFG3_GPIO16_ENABLE 0x01
+#define CFG3_CI_CLEAR 0x02
+#define CFG3_VREF_250 0x04
+#define CFG3_GPIO16_DIR 0x40
+#define CFG3_GPIO16_POL 0x80
+#define ADM1026_REG_E2CONFIG 0x13
+#define E2CFG_READ 0x01
+#define E2CFG_WRITE 0x02
+#define E2CFG_ERASE 0x04
+#define E2CFG_ROM 0x08
+#define E2CFG_CLK_EXT 0x80
+
+/* There are 10 general analog inputs and 7 dedicated inputs
+ * They are:
+ * 0 - 9 = AIN0 - AIN9
+ * 10 = Vbat
+ * 11 = 3.3V Standby
+ * 12 = 3.3V Main
+ * 13 = +5V
+ * 14 = Vccp (CPU core voltage)
+ * 15 = +12V
+ * 16 = -12V
+ */
+static u16 ADM1026_REG_IN[] = {
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
+ 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
+ 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
+ };
+static u16 ADM1026_REG_IN_MIN[] = {
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
+ 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
+ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+static u16 ADM1026_REG_IN_MAX[] = {
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
+ 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
+ 0x43, 0x44, 0x45, 0x46, 0x47
+ };
+
+/* Temperatures are:
+ * 0 - Internal
+ * 1 - External 1
+ * 2 - External 2
+ */
+static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
+static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
+static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
+static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
+static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
+static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
+
+#define ADM1026_REG_FAN(nr) (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3 0x02
+#define ADM1026_REG_FAN_DIV_4_7 0x03
+
+#define ADM1026_REG_DAC 0x04
+#define ADM1026_REG_PWM 0x05
+
+#define ADM1026_REG_GPIO_CFG_0_3 0x08
+#define ADM1026_REG_GPIO_CFG_4_7 0x09
+#define ADM1026_REG_GPIO_CFG_8_11 0x0a
+#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+/* CFG_16 in REG_CFG3 */
+#define ADM1026_REG_GPIO_STATUS_0_7 0x24
+#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+/* STATUS_16 in REG_STATUS4 */
+#define ADM1026_REG_GPIO_MASK_0_7 0x1c
+#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+/* MASK_16 in REG_MASK4 */
+
+#define ADM1026_REG_COMPANY 0x16
+#define ADM1026_REG_VERSTEP 0x17
+/* These are the recognized values for the above regs */
+#define ADM1026_COMPANY_ANALOG_DEV 0x41
+#define ADM1026_VERSTEP_GENERIC 0x40
+#define ADM1026_VERSTEP_ADM1026 0x44
+
+#define ADM1026_REG_MASK1 0x18
+#define ADM1026_REG_MASK2 0x19
+#define ADM1026_REG_MASK3 0x1a
+#define ADM1026_REG_MASK4 0x1b
+
+#define ADM1026_REG_STATUS1 0x20
+#define ADM1026_REG_STATUS2 0x21
+#define ADM1026_REG_STATUS3 0x22
+#define ADM1026_REG_STATUS4 0x23
+
+#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX 255
+
+/* 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.
+ */
+
+/* IN are scaled acording to built-in resistors. These are the
+ * voltages corresponding to 3/4 of full scale (192 or 0xc0)
+ * NOTE: The -12V input needs an additional factor to account
+ * for the Vref pullup resistor.
+ * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
+ * = 13875 * 2.50 / 1.875 - 2500
+ * = 16000
+ *
+ * The values in this table are based on Table II, page 15 of the
+ * datasheet.
+ */
+static int adm1026_scaling[] = { /* .001 Volts */
+ 2250, 2250, 2250, 2250, 2250, 2250,
+ 1875, 1875, 1875, 1875, 3000, 3330,
+ 3330, 4995, 2250, 12000, 13875
+ };
+#define NEG12_OFFSET 16000
+#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
+ 0,255))
+#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+
+/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
+ * and we assume a 2 pulse-per-rev fan tach signal
+ * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
+ */
+#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
+ (div)),1,254))
+#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
+ (div)))
+#define DIV_FROM_REG(val) (1<<(val))
+#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+
+/* Temperature is reported in 1 degC increments */
+#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define TEMP_FROM_REG(val) ((val) * 1000)
+#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define OFFSET_FROM_REG(val) ((val) * 1000)
+
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_FROM_REG(val) (val)
+
+#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
+#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
+
+/* Analog output is a voltage, and scaled to millivolts. The datasheet
+ * indicates that the DAC could be used to drive the fans, but in our
+ * example board (Arima HDAMA) it isn't connected to the fans at all.
+ */
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
+#define DAC_FROM_REG(val) (((val)*2500)/255)
+
+/* Typically used with systems using a v9.1 VRM spec ? */
+#define ADM1026_INIT_VRM 91
+
+/* Chip sampling rates
+ *
+ * Some sensors are not updated more frequently than once per second
+ * so it doesn't make sense to read them more often than that.
+ * We cache the results and return the saved data if the driver
+ * is called again before a second has elapsed.
+ *
+ * Also, there is significant configuration data for this chip
+ * So, we keep the config data up to date in the cache
+ * when it is written and only sample it once every 5 *minutes*
+ */
+#define ADM1026_DATA_INTERVAL (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
+
+/* We allow for multiple chips in a single system.
+ *
+ * For each registered ADM1026, we need to keep state information
+ * at client->data. The adm1026_data structure is dynamically
+ * allocated, when a new client structure is allocated. */
+
+struct pwm_data {
+ u8 pwm;
+ u8 enable;
+ u8 auto_pwm_min;
+};
+
+struct adm1026_data {
+ struct i2c_client client;
+ struct semaphore lock;
+ enum chips type;
+
+ struct semaphore update_lock;
+ int valid; /* !=0 if following fields are valid */
+ unsigned long last_reading; /* In jiffies */
+ unsigned long last_config; /* In jiffies */
+
+ u8 in[17]; /* Register value */
+ u8 in_max[17]; /* Register value */
+ u8 in_min[17]; /* Register value */
+ s8 temp[3]; /* Register value */
+ s8 temp_min[3]; /* Register value */
+ s8 temp_max[3]; /* Register value */
+ s8 temp_tmin[3]; /* Register value */
+ s8 temp_crit[3]; /* Register value */
+ s8 temp_offset[3]; /* Register value */
+ u8 fan[8]; /* Register value */
+ u8 fan_min[8]; /* Register value */
+ u8 fan_div[8]; /* Decoded value */
+ struct pwm_data pwm1; /* Pwm control values */
+ int vid; /* Decoded value */
+ u8 vrm; /* VRM version */
+ u8 analog_out; /* Register value (DAC) */
+ long alarms; /* Register encoding, combined */
+ long alarm_mask; /* Register encoding, combined */
+ long gpio; /* Register encoding, combined */
+ long gpio_mask; /* Register encoding, combined */
+ u8 gpio_config[17]; /* Decoded value */
+ u8 config1; /* Register value */
+ u8 config2; /* Register value */
+ u8 config3; /* Register value */
+};
+
+static int adm1026_attach_adapter(struct i2c_adapter *adapter);
+static int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind);
+static int adm1026_detach_client(struct i2c_client *client);
+static int adm1026_read_value(struct i2c_client *client, u8 register);
+static int adm1026_write_value(struct i2c_client *client, u8 register,
+ int value);
+static void adm1026_print_gpio(struct i2c_client *client);
+static void adm1026_fixup_gpio(struct i2c_client *client);
+static struct adm1026_data *adm1026_update_device(struct device *dev);
+static void adm1026_init_client(struct i2c_client *client);
+
+
+static struct i2c_driver adm1026_driver = {
+ .owner = THIS_MODULE,
+ .name = "adm1026",
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = adm1026_attach_adapter,
+ .detach_client = adm1026_detach_client,
+};
+
+static int adm1026_id;
+
+int adm1026_attach_adapter(struct i2c_adapter *adapter)
+{
+ if (!(adapter->class & I2C_CLASS_HWMON)) {
+ return 0;
+ }
+ return i2c_detect(adapter, &addr_data, adm1026_detect);
+}
+
+int adm1026_detach_client(struct i2c_client *client)
+{
+ i2c_detach_client(client);
+ kfree(client);
+ return 0;
+}
+
+int adm1026_read_value(struct i2c_client *client, u8 reg)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_read_byte_data(client, reg) & 0xff;
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_write_byte_data(client, reg, value);
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+void adm1026_init_client(struct i2c_client *client)
+{
+ int value, i;
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
+ /* Read chip config */
+ data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
+
+ /* Inform user of chip config */
+ dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
+ client->id, data->config1);
+ if ((data->config1 & CFG1_MONITOR) == 0) {
+ dev_dbg(&client->dev, "(%d): Monitoring not currently "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_INT_ENABLE) {
+ dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_AIN8_9) {
+ dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
+ "temp3 disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
+ "in9 disabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_THERM_HOT) {
+ dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
+ "and temp limits enabled.\n", client->id);
+ }
+
+ value = data->config3;
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
+ "pin disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): THERM pin enabled. "
+ "GPIO16 disabled.\n", client->id);
+ }
+ if (data->config3 & CFG3_VREF_250) {
+ dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
+ client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
+ client->id);
+ }
+ /* Read and pick apart the existing GPIO configuration */
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) == 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ /* ... and then print it */
+ adm1026_print_gpio(client);
+
+ /* If the user asks us to reprogram the GPIO config, then
+ * do it now. But only if this is the first ADM1026.
+ */
+ if (client->id == 0
+ && (gpio_input[0] != -1 || gpio_output[0] != -1
+ || gpio_inverted[0] != -1 || gpio_normal[0] != -1
+ || gpio_fan[0] != -1)) {
+ adm1026_fixup_gpio(client);
+ }
+
+ /* WE INTENTIONALLY make no changes to the limits,
+ * offsets, pwms, fans and zones. If they were
+ * configured, we don't want to mess with them.
+ * If they weren't, the default is 100% PWM, no
+ * control and will suffice until 'sensors -s'
+ * can be run by the user. We DO set the default
+ * value for pwm1.auto_pwm_min to its maximum
+ * so that enabling automatic pwm fan control
+ * without first setting a value for pwm1.auto_pwm_min
+ * will not result in potentially dangerous fan speed decrease.
+ */
+ data->pwm1.auto_pwm_min=255;
+ /* Start monitoring */
+ value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ /* Set MONITOR, clear interrupt acknowledge and s/w reset */
+ value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
+ dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
+ client->id, value);
+ data->config1 = value;
+ adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
+}
+
+void adm1026_print_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+
+ dev_dbg(&client->dev, "(%d): GPIO config is:",
+ client->id);
+ for (i = 0;i <= 7;++i) {
+ if (data->config2 & (1 << i)) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ } else {
+ dev_dbg(&client->dev, "\t(%d): FAN%d\n",
+ client->id, i);
+ }
+ }
+ for (i = 8;i <= 15;++i) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ }
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
+ data->gpio_config[16] & 0x02 ? "" : "!",
+ data->gpio_config[16] & 0x01 ? "OUT" : "IN");
+ } else {
+ /* GPIO16 is THERM */
+ dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
+ }
+}
+
+void adm1026_fixup_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ int value;
+
+ /* Make the changes requested. */
+ /* We may need to unlock/stop monitoring or soft-reset the
+ * chip before we can make changes. This hasn't been
+ * tested much. FIXME
+ */
+
+ /* Make outputs */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
+ data->gpio_config[gpio_output[i]] |= 0x01;
+ }
+ /* if GPIO0-7 is output, it isn't a FAN tach */
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
+ data->config2 |= 1 << gpio_output[i];
+ }
+ }
+
+ /* Input overrides output */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
+ data->gpio_config[gpio_input[i]] &= ~ 0x01;
+ }
+ /* if GPIO0-7 is input, it isn't a FAN tach */
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
+ data->config2 |= 1 << gpio_input[i];
+ }
+ }
+
+ /* Inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
+ data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
+ }
+ }
+
+ /* Normal overrides inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
+ data->gpio_config[gpio_normal[i]] |= 0x02;
+ }
+ }
+
+ /* Fan overrides input and output */
+ for (i = 0;i <= 7;++i) {
+ if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
+ data->config2 &= ~(1 << gpio_fan[i]);
+ }
+ }
+
+ /* Write new configs to registers */
+ adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
+ data->config3 = (data->config3 & 0x3f)
+ | ((data->gpio_config[16] & 0x03) << 6);
+ adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
+ for (i = 15, value = 0;i >= 0;--i) {
+ value <<= 2;
+ value |= data->gpio_config[i] & 0x03;
+ if ((i & 0x03) == 0) {
+ adm1026_write_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4,
+ value);
+ value = 0;
+ }
+ }
+
+ /* Print the new config */
+ adm1026_print_gpio(client);
+}
+
+
+static struct adm1026_data *adm1026_update_device(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ long value, alarms, gpio;
+
+ down(&data->update_lock);
+ if (!data->valid
+ || (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
+ /* Things that change quickly */
+ dev_dbg(&client->dev,"(%d): Reading sensor values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in[i] =
+ adm1026_read_value(client, ADM1026_REG_IN[i]);
+ }
+
+ for (i = 0;i <= 7;++i) {
+ data->fan[i] =
+ adm1026_read_value(client, ADM1026_REG_FAN(i));
+ }
+
+ for (i = 0;i <= 2;++i) {
+ /* NOTE: temp[] is s8 and we assume 2's complement
+ * "conversion" in the assignment */
+ data->temp[i] =
+ adm1026_read_value(client, ADM1026_REG_TEMP[i]);
+ }
+
+ data->pwm1.pwm = adm1026_read_value(client,
+ ADM1026_REG_PWM);
+ data->analog_out = adm1026_read_value(client,
+ ADM1026_REG_DAC);
+ /* GPIO16 is MSbit of alarms, move it to gpio */
+ alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms &= 0x7f;
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
+ data->alarms = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_0_7);
+ data->gpio = gpio;
+
+ data->last_reading = jiffies;
+ }; /* last_reading */
+
+ if (!data->valid || (jiffies - data->last_config >
+ ADM1026_CONFIG_INTERVAL)) {
+ /* Things that don't change often */
+ dev_dbg(&client->dev, "(%d): Reading config values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in_min[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MIN[i]);
+ data->in_max[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MAX[i]);
+ }
+
+ value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
+ | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
+ << 8);
+ for (i = 0;i <= 7;++i) {
+ data->fan_min[i] = adm1026_read_value(client,
+ ADM1026_REG_FAN_MIN(i));
+ data->fan_div[i] = DIV_FROM_REG(value & 0x03);
+ value >>= 2;
+ }
+
+ for (i = 0; i <= 2; ++i) {
+ /* NOTE: temp_xxx[] are s8 and we assume 2's
+ * complement "conversion" in the assignment
+ */
+ data->temp_min[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MIN[i]);
+ data->temp_max[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MAX[i]);
+ data->temp_tmin[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_TMIN[i]);
+ data->temp_crit[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_THERM[i]);
+ data->temp_offset[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_OFFSET[i]);
+ }
+
+ /* Read the STATUS/alarm masks */
+ alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms = (alarms & 0x7f) << 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
+ data->alarm_mask = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_MASK_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
+ data->gpio_mask = gpio;
+
+ /* Read various values from CONFIG1 */
+ data->config1 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG1);
+ if (data->config1 & CFG1_PWM_AFC) {
+ data->pwm1.enable = 2;
+ data->pwm1.auto_pwm_min =
+ PWM_MIN_FROM_REG(data->pwm1.pwm);
+ }
+ /* Read the GPIO config */
+ data->config2 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG3);
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) == 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+
+ data->last_config = jiffies;
+ }; /* last_config */
+
+ dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
+ client->id);
+ data->vid = (data->gpio >> 11) & 0x1f;
+ data->valid = 1;
+ up(&data->update_lock);
+ return data;
+}
+
+static ssize_t show_in(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+}
+static ssize_t show_in_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+}
+static ssize_t set_in_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+}
+static ssize_t set_in_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define in_reg(offset) \
+static ssize_t show_in##offset (struct device *dev, char *buf) \
+{ \
+ return show_in(dev, buf, offset); \
+} \
+static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_in_min(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_min(dev, buf, count, offset); \
+} \
+static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_in_max(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_max(dev, buf, count, offset); \
+} \
+static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
+static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
+ show_in##offset##_min, set_in##offset##_min); \
+static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
+ show_in##offset##_max, set_in##offset##_max);
+
+
+in_reg(0);
+in_reg(1);
+in_reg(2);
+in_reg(3);
+in_reg(4);
+in_reg(5);
+in_reg(6);
+in_reg(7);
+in_reg(8);
+in_reg(9);
+in_reg(10);
+in_reg(11);
+in_reg(12);
+in_reg(13);
+in_reg(14);
+in_reg(15);
+
+static ssize_t show_in16(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+ NEG12_OFFSET);
+}
+static ssize_t show_in16_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in16_max(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
+static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
+static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
+
+
+
+
+/* Now add fan read/write functions */
+
+static ssize_t show_fan(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+ data->fan_div[nr]));
+}
+static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+ data->fan_div[nr]));
+}
+static ssize_t set_fan_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
+ data->fan_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset(offset) \
+static ssize_t show_fan_##offset (struct device *dev, char *buf) \
+{ \
+ return show_fan(dev, buf, offset - 1); \
+} \
+static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_fan_min(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_min(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
+static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_min, set_fan_##offset##_min);
+
+fan_offset(1);
+fan_offset(2);
+fan_offset(3);
+fan_offset(4);
+fan_offset(5);
+fan_offset(6);
+fan_offset(7);
+fan_offset(8);
+
+/* Adjust fan_min to account for new fan divisor */
+void fixup_fan_min(struct device *dev, int fan, int old_div)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int new_min;
+ int new_div = data->fan_div[fan];
+
+ /* 0 and 0xff are special. Don't adjust them */
+ if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
+ return;
+ }
+
+ new_min = data->fan_min[fan] * old_div / new_div;
+ new_min = SENSORS_LIMIT(new_min, 1, 254);
+ data->fan_min[fan] = new_min;
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
+}
+
+/* Now add fan_div read/write functions */
+static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->fan_div[nr]);
+}
+static ssize_t set_fan_div(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val,orig_div,new_div,shift;
+
+ val = simple_strtol(buf, NULL, 10);
+ new_div = DIV_TO_REG(val);
+ if (new_div == 0) {
+ return -EINVAL;
+ }
+ down(&data->update_lock);
+ orig_div = data->fan_div[nr];
+ data->fan_div[nr] = DIV_FROM_REG(new_div);
+
+ if (nr < 4) { /* 0 <= nr < 4 */
+ shift = 2 * nr;
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
+ (new_div << shift)));
+ } else { /* 3 < nr < 8 */
+ shift = 2 * (nr - 4);
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
+ (new_div << shift)));
+ }
+
+ if (data->fan_div[nr] != orig_div) {
+ fixup_fan_min(dev,nr,orig_div);
+ }
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset_div(offset) \
+static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
+{ \
+ return show_fan_div(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_div (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_div(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_div, set_fan_##offset##_div);
+
+fan_offset_div(1);
+fan_offset_div(2);
+fan_offset_div(3);
+fan_offset_div(4);
+fan_offset_div(5);
+fan_offset_div(6);
+fan_offset_div(7);
+fan_offset_div(8);
+
+/* Temps */
+static ssize_t show_temp(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+}
+static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+}
+static ssize_t set_temp_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_min[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
+ data->temp_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+}
+static ssize_t set_temp_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_max[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
+ data->temp_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+#define temp_reg(offset) \
+static ssize_t show_temp_##offset (struct device *dev, char *buf) \
+{ \
+ return show_temp(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_temp_min(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_temp_max(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_min(dev, buf, count, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_max(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
+static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_min, set_temp_##offset##_min); \
+static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_max, set_temp_##offset##_max);
+
+
+temp_reg(1);
+temp_reg(2);
+temp_reg(3);
+
+static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+}
+static ssize_t set_temp_offset(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_offset[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
+ data->temp_offset[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_offset_reg(offset) \
+static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
+{ \
+ return show_temp_offset(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_offset (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_offset(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_offset, set_temp_##offset##_offset);
+
+temp_offset_reg(1);
+temp_offset_reg(2);
+temp_offset_reg(3);
+
+static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(
+ ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
+}
+static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+ ADM1026_FAN_CONTROL_TEMP_RANGE));
+}
+static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+}
+static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_tmin[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
+ data->temp_tmin[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_auto_point(offset) \
+static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point1_temp(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
+ *dev, char *buf) \
+{ \
+ return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point2_temp(dev, buf, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
+ show_temp##offset##_auto_point1_temp, \
+ set_temp##offset##_auto_point1_temp); \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
+ show_temp##offset##_auto_point1_temp_hyst, NULL); \
+static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
+ show_temp##offset##_auto_point2_temp, NULL);
+
+temp_auto_point(1);
+temp_auto_point(2);
+temp_auto_point(3);
+
+static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+}
+static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val == 1) || (val==0)) {
+ down(&data->update_lock);
+ data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+
+static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+}
+static ssize_t set_temp_crit(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_crit[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
+ data->temp_crit[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_crit_reg(offset) \
+static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
+{ \
+ return show_temp_crit(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_crit (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_crit(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_crit, set_temp_##offset##_crit);
+
+temp_crit_reg(1);
+temp_crit_reg(2);
+temp_crit_reg(3);
+
+static ssize_t show_analog_out_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+}
+static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->analog_out = DAC_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
+ set_analog_out_reg);
+
+static ssize_t show_vid_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+}
+
+static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
+
+static ssize_t show_vrm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->vrm);
+}
+static ssize_t store_vrm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ data->vrm = simple_strtol(buf, NULL, 10);
+ return count;
+}
+
+static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
+
+static ssize_t show_alarms_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf, "%ld\n", (long) (data->alarms));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
+
+static ssize_t show_alarm_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->alarm_mask);
+}
+static ssize_t set_alarm_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ unsigned long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->alarm_mask = val & 0x7fffffff;
+ mask = data->alarm_mask
+ | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
+ adm1026_write_value(client, ADM1026_REG_MASK1,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK2,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK3,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK4,
+ mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
+ set_alarm_mask);
+
+
+static ssize_t show_gpio(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio);
+}
+static ssize_t set_gpio(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long gpio;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio = val & 0x1ffff;
+ gpio = data->gpio;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+ gpio >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+ gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
+
+
+static ssize_t show_gpio_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio_mask);
+}
+static ssize_t set_gpio_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio_mask = val & 0x1ffff;
+ mask = data->gpio_mask;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+ mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
+
+static ssize_t show_pwm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
+}
+static ssize_t set_pwm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ if (data->pwm1.enable == 1) {
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.pwm = PWM_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ up(&data->update_lock);
+ }
+ return count;
+}
+static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
+}
+static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
+ if (data->pwm1.enable == 2) { /* apply immediately */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
+{
+ return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
+}
+static ssize_t show_pwm_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.enable);
+}
+static ssize_t set_pwm_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ int old_enable;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val >= 0) && (val < 3)) {
+ down(&data->update_lock);
+ old_enable = data->pwm1.enable;
+ data->pwm1.enable = val;
+ data->config1 = (data->config1 & ~CFG1_PWM_AFC)
+ | ((val == 2) ? CFG1_PWM_AFC : 0);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ } else if (!((old_enable == 1) && (val == 1))) {
+ /* set pwm to safe value */
+ data->pwm1.pwm = 255;
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+/* enable PWM fan control */
+static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+
+static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+
+int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind)
+{
+ int company, verstep;
+ struct i2c_client *new_client;
+ struct adm1026_data *data;
+ int err = 0;
+ const char *type_name = "";
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+ /* We need to be able to do byte I/O */
+ goto exit;
+ };
+
+ /* 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 adm1026_{read,write}_value. */
+
+ if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ memset(data, 0, sizeof(struct adm1026_data));
+
+ new_client = &data->client;
+ i2c_set_clientdata(new_client, data);
+ new_client->addr = address;
+ new_client->adapter = adapter;
+ new_client->driver = &adm1026_driver;
+ new_client->flags = 0;
+
+ /* Now, we do the remaining detection. */
+
+ company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
+ verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
+
+ dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
+ " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
+ i2c_adapter_id(new_client->adapter), new_client->addr,
+ company, verstep);
+
+ /* If auto-detecting, Determine the chip type. */
+ if (kind <= 0) {
+ dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
+ "...\n", i2c_adapter_id(adapter), address);
+ if (company == ADM1026_COMPANY_ANALOG_DEV
+ && verstep == ADM1026_VERSTEP_ADM1026) {
+ kind = adm1026;
+ } else if (company == ADM1026_COMPANY_ANALOG_DEV
+ && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Unrecognized stepping "
+ "0x%02x. Defaulting to ADM1026.\n", verstep);
+ kind = adm1026;
+ } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Found version/stepping "
+ "0x%02x. Assuming generic ADM1026.\n",
+ verstep);
+ kind = any_chip;
+ } else {
+ dev_dbg(&new_client->dev, ": Autodetection "
+ "failed\n");
+ /* Not an ADM1026 ... */
+ if (kind == 0) { /* User used force=x,y */
+ dev_err(&adapter->dev, "Generic ADM1026 not "
+ "found at %d,0x%02x. Try "
+ "force_adm1026.\n",
+ i2c_adapter_id(adapter), address);
+ }
+ err = 0;
+ goto exitfree;
+ }
+ }
+
+ /* Fill in the chip specific driver values */
+ switch (kind) {
+ case any_chip :
+ type_name = "adm1026";
+ break;
+ case adm1026 :
+ type_name = "adm1026";
+ break;
+ default :
+ dev_err(&adapter->dev, ": Internal error, invalid "
+ "kind (%d)!", kind);
+ err = -EFAULT;
+ goto exitfree;
+ }
+ strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
+
+ /* Fill in the remaining client fields */
+ new_client->id = adm1026_id++;
+ data->type = kind;
+ data->valid = 0;
+ init_MUTEX(&data->update_lock);
+
+ dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
+ new_client->id, new_client->id, new_client->name,
+ i2c_adapter_id(new_client->adapter),
+ new_client->addr);
+
+ /* Tell the I2C layer a new client has arrived */
+ if ((err = i2c_attach_client(new_client)))
+ goto exitfree;
+
+ /* Set the VRM version */
+ data->vrm = i2c_which_vrm();
+
+ /* Initialize the ADM1026 chip */
+ adm1026_init_client(new_client);
+
+ /* Register sysfs hooks */
+ device_create_file(&new_client->dev, &dev_attr_in0_input);
+ device_create_file(&new_client->dev, &dev_attr_in0_max);
+ device_create_file(&new_client->dev, &dev_attr_in0_min);
+ device_create_file(&new_client->dev, &dev_attr_in1_input);
+ device_create_file(&new_client->dev, &dev_attr_in1_max);
+ device_create_file(&new_client->dev, &dev_attr_in1_min);
+ device_create_file(&new_client->dev, &dev_attr_in2_input);
+ device_create_file(&new_client->dev, &dev_attr_in2_max);
+ device_create_file(&new_client->dev, &dev_attr_in2_min);
+ device_create_file(&new_client->dev, &dev_attr_in3_input);
+ device_create_file(&new_client->dev, &dev_attr_in3_max);
+ device_create_file(&new_client->dev, &dev_attr_in3_min);
+ device_create_file(&new_client->dev, &dev_attr_in4_input);
+ device_create_file(&new_client->dev, &dev_attr_in4_max);
+ device_create_file(&new_client->dev, &dev_attr_in4_min);
+ device_create_file(&new_client->dev, &dev_attr_in5_input);
+ device_create_file(&new_client->dev, &dev_attr_in5_max);
+ device_create_file(&new_client->dev, &dev_attr_in5_min);
+ device_create_file(&new_client->dev, &dev_attr_in6_input);
+ device_create_file(&new_client->dev, &dev_attr_in6_max);
+ device_create_file(&new_client->dev, &dev_attr_in6_min);
+ device_create_file(&new_client->dev, &dev_attr_in7_input);
+ device_create_file(&new_client->dev, &dev_attr_in7_max);
+ device_create_file(&new_client->dev, &dev_attr_in7_min);
+ device_create_file(&new_client->dev, &dev_attr_in8_input);
+ device_create_file(&new_client->dev, &dev_attr_in8_max);
+ device_create_file(&new_client->dev, &dev_attr_in8_min);
+ device_create_file(&new_client->dev, &dev_attr_in9_input);
+ device_create_file(&new_client->dev, &dev_attr_in9_max);
+ device_create_file(&new_client->dev, &dev_attr_in9_min);
+ device_create_file(&new_client->dev, &dev_attr_in10_input);
+ device_create_file(&new_client->dev, &dev_attr_in10_max);
+ device_create_file(&new_client->dev, &dev_attr_in10_min);
+ device_create_file(&new_client->dev, &dev_attr_in11_input);
+ device_create_file(&new_client->dev, &dev_attr_in11_max);
+ device_create_file(&new_client->dev, &dev_attr_in11_min);
+ device_create_file(&new_client->dev, &dev_attr_in12_input);
+ device_create_file(&new_client->dev, &dev_attr_in12_max);
+ device_create_file(&new_client->dev, &dev_attr_in12_min);
+ device_create_file(&new_client->dev, &dev_attr_in13_input);
+ device_create_file(&new_client->dev, &dev_attr_in13_max);
+ device_create_file(&new_client->dev, &dev_attr_in13_min);
+ device_create_file(&new_client->dev, &dev_attr_in14_input);
+ device_create_file(&new_client->dev, &dev_attr_in14_max);
+ device_create_file(&new_client->dev, &dev_attr_in14_min);
+ device_create_file(&new_client->dev, &dev_attr_in15_input);
+ device_create_file(&new_client->dev, &dev_attr_in15_max);
+ device_create_file(&new_client->dev, &dev_attr_in15_min);
+ device_create_file(&new_client->dev, &dev_attr_in16_input);
+ device_create_file(&new_client->dev, &dev_attr_in16_max);
+ device_create_file(&new_client->dev, &dev_attr_in16_min);
+ device_create_file(&new_client->dev, &dev_attr_fan1_input);
+ device_create_file(&new_client->dev, &dev_attr_fan1_div);
+ device_create_file(&new_client->dev, &dev_attr_fan1_min);
+ device_create_file(&new_client->dev, &dev_attr_fan2_input);
+ device_create_file(&new_client->dev, &dev_attr_fan2_div);
+ device_create_file(&new_client->dev, &dev_attr_fan2_min);
+ device_create_file(&new_client->dev, &dev_attr_fan3_input);
+ device_create_file(&new_client->dev, &dev_attr_fan3_div);
+ device_create_file(&new_client->dev, &dev_attr_fan3_min);
+ device_create_file(&new_client->dev, &dev_attr_fan4_input);
+ device_create_file(&new_client->dev, &dev_attr_fan4_div);
+ device_create_file(&new_client->dev, &dev_attr_fan4_min);
+ device_create_file(&new_client->dev, &dev_attr_fan5_input);
+ device_create_file(&new_client->dev, &dev_attr_fan5_div);
+ device_create_file(&new_client->dev, &dev_attr_fan5_min);
+ device_create_file(&new_client->dev, &dev_attr_fan6_input);
+ device_create_file(&new_client->dev, &dev_attr_fan6_div);
+ device_create_file(&new_client->dev, &dev_attr_fan6_min);
+ device_create_file(&new_client->dev, &dev_attr_fan7_input);
+ device_create_file(&new_client->dev, &dev_attr_fan7_div);
+ device_create_file(&new_client->dev, &dev_attr_fan7_min);
+ device_create_file(&new_client->dev, &dev_attr_fan8_input);
+ device_create_file(&new_client->dev, &dev_attr_fan8_div);
+ device_create_file(&new_client->dev, &dev_attr_fan8_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_input);
+ device_create_file(&new_client->dev, &dev_attr_temp1_max);
+ device_create_file(&new_client->dev, &dev_attr_temp1_min);
+ device_create_file(&new_client->dev, &dev_attr_temp2_input);
+ device_create_file(&new_client->dev, &dev_attr_temp2_max);
+ device_create_file(&new_client->dev, &dev_attr_temp2_min);
+ device_create_file(&new_client->dev, &dev_attr_temp3_input);
+ device_create_file(&new_client->dev, &dev_attr_temp3_max);
+ device_create_file(&new_client->dev, &dev_attr_temp3_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp2_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp3_offset);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point2_temp);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_vid);
+ device_create_file(&new_client->dev, &dev_attr_vrm);
+ device_create_file(&new_client->dev, &dev_attr_alarms);
+ device_create_file(&new_client->dev, &dev_attr_alarm_mask);
+ device_create_file(&new_client->dev, &dev_attr_gpio);
+ device_create_file(&new_client->dev, &dev_attr_gpio_mask);
+ device_create_file(&new_client->dev, &dev_attr_pwm1);
+ device_create_file(&new_client->dev, &dev_attr_pwm2);
+ device_create_file(&new_client->dev, &dev_attr_pwm3);
+ device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_analog_out);
+ return 0;
+
+ /* Error out and cleanup code */
+exitfree:
+ kfree(new_client);
+exit:
+ return err;
+}
+static int __init sm_adm1026_init(void)
+{
+ return i2c_add_driver(&adm1026_driver);
+}
+
+static void __exit sm_adm1026_exit(void)
+{
+ i2c_del_driver(&adm1026_driver);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
+ "Justin Thiessen <jthiessen@penguincomputing.com>");
+MODULE_DESCRIPTION("ADM1026 driver");
+
+module_init(sm_adm1026_init);
+module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
@ 2005-05-19 6:25 Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
` (9 more replies)
0 siblings, 10 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi,
I have ported Phil Pokorny's adm1026 driver for the 2.6.X kernel, following
the guide in /usr/src/linux/Documentation/i2c/porting-clients, referring
to the lm78 driver for examples, and adhering to the 4th auto-fan proposal
as outline recently by Jean Delvare.
Most of the code is essentially still Phil's. My contributions fall into
3 categories:
(1) Changes necessitated by the switch from procfs to sysfs interface.
(2) Fan control code following the 4th auto-fan proposal model.
(3) Other, minor housekeeping updates dictated by the aforementioned
"porting-clients" file.
The driver has been tested with an Arima HDAMA-based system.
As always, feedback is welcome.
Justin Thiessen
----------------
jthiessen@penguincomputing.com
Signed-off-by: Justin Thiessen
-------------
Code follows:
-------------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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.
CHANGELOG
2003-03-13 Initial development
2003-05-07 First Release. Includes GPIO fixup and full
functionality.
2003-05-18 Minor fixups and tweaks.
Print GPIO config after fixup.
Adjust fan MIN if DIV changes.
2003-05-21 Fix printing of FAN/GPIO config
Fix silly bug in fan_div logic
Fix fan_min handling so that 0xff is 0 is 0xff
2003-05-25 Fix more silly typos...
2003-06-11 Change FAN_xx_REG macros to use different scaling
Most (all?) drivers assume two pulses per rev fans
and the old scaling was producing double the RPM's
Thanks to Jerome Hsiao @ Arima for pointing this out.
2004-01-27 Remove use of temporary ID. Define addresses as a range.
2004-10-18 Port to kernel 2.6.X and sysfs interface.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 (0x00)
#define CFG1_MONITOR (0x01)
#define CFG1_INT_ENABLE (0x02)
#define CFG1_INT_CLEAR (0x04)
#define CFG1_AIN8_9 (0x08)
#define CFG1_THERM_HOT (0x10)
#define CFG1_DAC_AFC (0x20)
#define CFG1_PWM_AFC (0x40)
#define CFG1_RESET (0x80)
#define ADM1026_REG_CONFIG2 (0x01)
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 (0x07)
#define CFG3_GPIO16_ENABLE (0x01)
#define CFG3_CI_CLEAR (0x02)
#define CFG3_VREF_250 (0x04)
#define CFG3_GPIO16_DIR (0x40)
#define CFG3_GPIO16_POL (0x80)
#define ADM1026_REG_E2CONFIG (0x13)
#define E2CFG_READ (0x01)
#define E2CFG_WRITE (0x02)
#define E2CFG_ERASE (0x04)
#define E2CFG_ROM (0x08)
#define E2CFG_CLK_EXT (0x80)
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
#define ADM1026_REG_IN(nr) (REG_IN[(nr)])
#define ADM1026_REG_IN_MIN(nr) (REG_IN_MIN[(nr)])
#define ADM1026_REG_IN_MAX(nr) (REG_IN_MAX[(nr)])
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_TEMP(nr) (REG_TEMP[(nr)])
#define ADM1026_REG_TEMP_MIN(nr) (REG_TEMP_MIN[(nr)])
#define ADM1026_REG_TEMP_MAX(nr) (REG_TEMP_MAX[(nr)])
#define ADM1026_REG_TEMP_TMIN(nr) (REG_TEMP_TMIN[(nr)])
#define ADM1026_REG_TEMP_THERM(nr) (REG_TEMP_THERM[(nr)])
#define ADM1026_REG_TEMP_OFFSET(nr) (REG_TEMP_OFFSET[(nr)])
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 (0x02)
#define ADM1026_REG_FAN_DIV_4_7 (0x03)
#define ADM1026_REG_DAC (0x04)
#define ADM1026_REG_PWM (0x05)
#define ADM1026_REG_GPIO_CFG_0_3 (0x08)
#define ADM1026_REG_GPIO_CFG_4_7 (0x09)
#define ADM1026_REG_GPIO_CFG_8_11 (0x0a)
#define ADM1026_REG_GPIO_CFG_12_15 (0x0b)
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 (0x24)
#define ADM1026_REG_GPIO_STATUS_8_15 (0x25)
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 (0x1c)
#define ADM1026_REG_GPIO_MASK_8_15 (0x1d)
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*/
#if 1
/* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#else
/* The values in this table are based on the resistors in
* Figure 5 on page 16. But the 3.3V inputs are not in
* the figure and the values for the 5V input are wrong.
* For 5V, I'm guessing that R2 at 55.2k is right, but
* the total resistance should be 1400 or 1449 like the
* other inputs. Using 1449, gives 4.922V at 192.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2249, 2249, 2249, 2249, 2249, 2249,
1875, 1875, 1875, 1875, 3329, 3329,
3329, 4922, 2249, 11969, 13889
};
#define NEG12_OFFSET 16019
#endif
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#if 0 /* If we have extended A/D bits */
#define INSEXT_FROM_REG(n,val,ext) (SCALE((val)*4 + (ext),192*4,\
adm1026_scaling[n]))
#define INS_FROM_REG(n,val) (INSEXT_FROM_REG(n,val,0))
#else
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
#endif
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT((val+500)/1000,-127,127))
#define TEMP_FROM_REG(val) (val * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT((val+500)/1000,-127,127))
#define OFFSET_FROM_REG(val) (val * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
/* Analog output is a voltage, but it's used like a PWM
* Seems like this should be scaled, but to be consistent
* with other drivers, we do it this way.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define DAC_FROM_REG(val) (val)
/* sensors_vid.h defines vid_from_reg() */
#define VID_FROM_REG(val,vrm) (vid_from_reg(val,vrm))
#define ALARMS_FROM_REG(val) (val)
/* Unlike some other drivers we DO NOT set initial limits. Use
* the config file to set limits.
*/
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
#define ADM1026_INIT_VID -1
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_therm[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm[2]; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
/* .id = I2C_DRIVERID_ADM1026, */
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
/* Unique ID assigned to each ADM1026 detected */
static int adm1026_id = 0;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_ADAP_CLASS_SMBUS)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if( reg < 0x80 ) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff ;
} else {
/* EEPROM, do nothing */
res = 0 ;
}
return res ;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res ;
if( reg < 0x80 ) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0 ;
}
return res ;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev, "adm1026(%d): Initializing device\n",
client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "adm1026(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1 );
if( (data->config1 & CFG1_MONITOR) = 0 ) {
dev_dbg(&client->dev, "adm1026(%d): Monitoring not currently "
"enabled.\n", client->id );
}
if( data->config1 & CFG1_INT_ENABLE ) {
dev_dbg(&client->dev, "adm1026(%d): SMBALERT interrupts are "
"enabled.\n", client->id );
}
if( data->config1 & CFG1_AIN8_9 ) {
dev_dbg(&client->dev, "adm1026(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id );
} else {
dev_dbg(&client->dev, "adm1026(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id );
}
if( data->config1 & CFG1_THERM_HOT ) {
dev_dbg(&client->dev, "adm1026(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id );
}
value = data->config3 ;
if( data->config3 & CFG3_GPIO16_ENABLE ) {
dev_dbg(&client->dev, "adm1026(%d): GPIO16 enabled. THERM "
"pin disabled.\n", client->id );
} else {
dev_dbg(&client->dev, "adm1026(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id );
}
if( data->config3 & CFG3_VREF_250 ) {
dev_dbg(&client->dev, "adm1026(%d): Vref is 2.50 Volts.\n",
client->id );
} else {
dev_dbg(&client->dev, "adm1026(%d): Vref is 1.82 Volts.\n",
client->id );
}
/* Read and pick apart the existing GPIO configuration */
value = 0 ;
for( i = 0 ; i <= 15 ; ++i ) {
if( (i & 0x03) = 0 ) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4 );
}
data->gpio_config[i] = value & 0x03 ;
value >>= 2 ;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03 ;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if( client->id = 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1 ) ) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* values for pwm[N].auto_pwm_min to their maximum
* so that enabling automatic pwm fan control
* without first setting a value for the associated
* pwm[N].auto_pwm_min will not result in potentially
* dangerous fan speed decrease.
*/
data->pwm[0].auto_pwm_min\x15;
data->pwm[1].auto_pwm_min\x15;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET) ;
dev_dbg(&client->dev, "adm1026(%d): Setting CONFIG to: 0x%02x\n",
client->id, value );
data->config1 = value ;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i ;
dev_dbg(&client->dev, "adm1026(%d): GPIO config is:\nadm1026(%d):",
client->id, client->id );
for( i = 0 ; i <= 7 ; ++i ) {
if( data->config2 & (1 << i) ) {
dev_dbg(&client->dev, " %sGP%s%d",
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i );
} else {
dev_dbg(&client->dev, " FAN%d", i );
}
}
dev_dbg(&client->dev, "\nadm1026(%d):", client->id );
for( i = 8 ; i <= 15 ; ++i ) {
dev_dbg(&client->dev, " %sGP%s%d",
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i );
}
if( data->config3 & CFG3_GPIO16_ENABLE ) {
dev_dbg(&client->dev, " %sGP%s16\n",
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN" );
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, " THERM\n" );
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i ;
int value ;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for( i = 0 ; i <= 16 ; ++i ) {
if( gpio_output[i] >= 0 && gpio_output[i] <= 16 ) {
data->gpio_config[gpio_output[i]] |= 0x01 ;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if( gpio_output[i] >= 0 && gpio_output[i] <= 7 ) {
data->config2 |= 1 << gpio_output[i] ;
}
}
/* Input overrides output */
for( i = 0 ; i <= 16 ; ++i ) {
if( gpio_input[i] >= 0 && gpio_input[i] <= 16 ) {
data->gpio_config[gpio_input[i]] &= ~ 0x01 ;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if( gpio_input[i] >= 0 && gpio_input[i] <= 7 ) {
data->config2 |= 1 << gpio_input[i] ;
}
}
/* Inverted */
for( i = 0 ; i <= 16 ; ++i ) {
if( gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16 ) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02 ;
}
}
/* Normal overrides inverted */
for( i = 0 ; i <= 16 ; ++i ) {
if( gpio_normal[i] >= 0 && gpio_normal[i] <= 16 ) {
data->gpio_config[gpio_normal[i]] |= 0x02 ;
}
}
/* Fan overrides input and output */
for( i = 0 ; i <= 7 ; ++i ) {
if( gpio_fan[i] >= 0 && gpio_fan[i] <= 7 ) {
data->config2 &= ~( 1 << gpio_fan[i] );
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6) ;
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for( i = 15, value = 0 ; i >= 0 ; --i ) {
value <<= 2 ;
value |= data->gpio_config[i] & 0x03 ;
if( (i & 0x03) = 0 ) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value );
value = 0 ;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio ;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL )) {
/* Things that change quickly */
dev_dbg(&client->dev,"adm1026(%d): Reading sensor values\n",
client->id);
for (i = 0 ; i <= 16 ; ++i) {
data->in[i] adm1026_read_value(client, ADM1026_REG_IN(i));
}
for (i = 0 ; i <= 7 ; ++i) {
data->fan[i] adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0 ; i <= 2 ; ++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] adm1026_read_value(client, ADM1026_REG_TEMP(i));
}
data->pwm[0].pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->pwm[1].pwm = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0 ; /* GPIO16 */
alarms &= 0x7f ;
alarms <<= 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms ;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8 ;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio ;
data->last_reading = jiffies ;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL) ) {
/* Things that don't change often */
dev_dbg(&client->dev, "adm1026(%d): Reading config values\n",
client->id);
for (i = 0 ; i <= 16 ; ++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN(i));
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX(i));
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0 ; i <= 7 ; ++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2 ;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN(i));
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX(i));
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN(i));
data->temp_therm[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM(i));
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET(i));
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0 ; /* GPIO16 */
alarms = (alarms & 0x7f) << 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8 ;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms ;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8 ;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio ;
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03 ;
value = 0 ;
for( i = 0 ; i <= 15 ; ++i ) {
if( (i & 0x03) = 0 ) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4 );
}
data->gpio_config[i] = value & 0x03 ;
value >>= 2 ;
}
data->last_config = jiffies;
}; /* last_config */
/* We don't know where or even _if_ the VID might be on the GPIO
* pins. But the datasheet gives an example config showing
* GPIO11-15 being used to monitor VID0-4, so we go with that
* but make the vid WRITEABLE so if it's wrong, the user can
* set it in /etc/sensors.conf perhaps using an expression or
* 0 to trigger a re-read from the GPIO pins.
*/
if( data->vid = ADM1026_INIT_VID ) {
/* Hasn't been set yet, make a bold assumption */
dev_dbg(&client->dev, "adm1026(%d): Setting VID from "
"GPIO11-15.\n", client->id );
data->vid = (data->gpio >> 11) & 0x1f ;
}
data->valid = 1;
up(&data->update_lock);
return data;
}
/*
*
* Translating functions below
*
*/
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
if (nr = 16) {
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) -
NEG12_OFFSET );
} else {
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) );
}
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
if (nr = 16) {
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr])
- NEG12_OFFSET );
} else {
return sprintf(buf,"%d\n", INS_FROM_REG(nr,
data->in_min[nr])); }
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
if (nr = 16) {
data->in_min[nr] = INS_TO_REG(nr, val + NEG12_OFFSET);
} else {
data->in_min[nr] = INS_TO_REG(nr, val);
}
adm1026_write_value(client, ADM1026_REG_IN_MIN(nr), data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
if (nr = 16) {
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr])
- NEG12_OFFSET );
} else {
return sprintf(buf,"%d\n", INS_FROM_REG(nr,
data->in_max[nr]));
}
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
if (nr = 16) {
data->in_max[nr] = INS_TO_REG(nr, val+NEG12_OFFSET);
} else {
data->in_max[nr] = INS_TO_REG(nr, val);
}
adm1026_write_value(client, ADM1026_REG_IN_MAX(nr), data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in_##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in_##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t show_in_##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t set_in_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in_##offset, NULL) \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in_##offset##_min, set_in_##offset##_min) \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in_##offset##_max, set_in_##offset##_max)
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
in_reg(16); /* special-casing in16 but still lumping in with other in# */
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]) );
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]) );
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL) \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min)
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan] ;
/* 0 and 0xff are special. Don't adjust them */
if( data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff ) {
return ;
}
new_min = data->fan_min[fan] * old_div / new_div ;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min ;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
orig_div = data->fan_div[nr];
new_div = DIV_TO_REG(val);
data->fan_div[nr] = DIV_FROM_REG(new_div);
if ( nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if ( data->fan_div[nr] != orig_div ) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div)
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]) );
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN(nr),
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX(nr),
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL) \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min) \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max)
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]) );
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET(nr),
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset)
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
return sprintf(buf,"%d\n",
TEMP_FROM_REG(ADM1026_FAN_ACTIVATION_TEMP_HYST));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG((data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE)));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]) );
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN(nr),
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp) \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL) \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL)
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_therm(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_therm[nr]) );
}
static ssize_t set_temp_therm(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_therm[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM(nr),
data->temp_therm[nr]);
up(&data->update_lock);
return count;
}
#define temp_therm_reg(offset) \
static ssize_t show_temp_##offset##_therm (struct device *dev, char *buf) \
{ \
return show_temp_therm(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_therm (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_therm(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_therm, S_IRUGO | S_IWUSR, \
show_temp_##offset##_therm, set_temp_##offset##_therm)
temp_therm_reg(1);
temp_therm_reg(2);
temp_therm_reg(3);
/* static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out) );
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg)
*/
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", VID_FROM_REG(data->vid & 0x3f, data->vrm));
}
static ssize_t set_vid_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ( val > 0 ) {
data->vid = val & 0x3f;
} else {
data->vid = ADM1026_INIT_VID;
}
return count;
}
static DEVICE_ATTR(vid, S_IRUGO | S_IWUSR, show_vid_reg, set_vid_reg)
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm );
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg)
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL)
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask );
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff ;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0) ;
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8 ;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8 ;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8 ;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask)
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio );
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock) ;
val = simple_strtol(buf, NULL, 10) ;
data->gpio = val & 0x1ffff ;
gpio = data->gpio ;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8 ;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1 ) & 0x80) | (data->alarms >> 24 & 0x7f) ;
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff) ;
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio)
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask );
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1 ) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask)
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count, int nr)
{
if ( nr = 0 ) {
adm1026_write_value(client, ADM1026_REG_PWM,
data->pwm[nr].pwm);
} else { /* setting DAC rather than PWM */
adm1026_write_value(client, ADM1026_REG_DAC,
data->pwm[nr].pwm);
}
up(&data->update_lock);
return count;
}
static ssize_t show_pwm_reg(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr].pwm) );
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if ( data->pwm[nr].enable = 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm[nr].pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count, nr);
}
return count;
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count, int nr)
{
data->pwm[nr].pwm = PWM_TO_REG((data->pwm[nr].pwm & 0x0f) |
(data->pwm[nr].auto_pwm_min << 4));
if ( nr = 0 ) {
adm1026_write_value(client, ADM1026_REG_PWM,
data->pwm[nr].pwm);
} else { /* setting DAC rather than PWM */
adm1026_write_value(client, ADM1026_REG_DAC,
data->pwm[nr].pwm);
}
up(&data->update_lock);
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm[nr].auto_pwm_min);
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm[nr].auto_pwm_min = SENSORS_LIMIT(val,0,15);
if (data->pwm[nr].enable = 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count, nr);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm[nr].enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm[nr].enable;
val = simple_strtol(buf, NULL, 10);
if (( val >= 0 ) && ( val < 3 )) {
data->pwm[nr].enable = val;
if ( nr = 0 ) { /* configure PWM access */
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| (( val = 2 ) ? CFG1_PWM_AFC : 0) ;
} else if ( nr = 1 ) { /* configure DAC access */
data->config1 = (data->config1 & ~CFG1_DAC_AFC)
| (( val = 2 ) ? CFG1_DAC_AFC : 0) ;
}
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if ( val = 2 ) { /* apply pwmN_auto_pwm_min to pwmN */
return store_auto_pwm_min(client, data, count, nr);
} else if (!((old_enable = 1) && (val = 1))) {
/* set pwm to safe value */
data->pwm[nr].pwm = 255;
return store_pwm_reg(client, data, count, nr);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
#define pwm_control(offset) \
static ssize_t show_pwm##offset(struct device *dev, char *buf) \
{ \
return show_pwm_reg(dev, buf, offset -1); \
} \
static ssize_t set_pwm##offset (struct device *dev, const char *buf, \
size_t count) \
{ \
return set_pwm_reg(dev, buf, count, offset -1); \
} \
static ssize_t show_pwm##offset##_enable(struct device *dev, char *buf) \
{ \
return show_pwm_enable(dev, buf, offset -1 ); \
} \
static ssize_t set_pwm##offset##_enable (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_pwm_enable(dev, buf, count, offset -1); \
} \
static ssize_t show_pwm##offset##_auto_pwm_min(struct device *dev, \
char *buf) \
{ \
return show_auto_pwm_min(dev, buf, offset -1); \
} \
static ssize_t set_pwm##offset##_auto_pwm_min(struct device *dev, \
const char *buf, size_t count) \
{ \
return set_auto_pwm_min(dev, buf, count, offset -1); \
} \
static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, show_pwm##offset, \
set_pwm##offset) \
static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
show_pwm##offset##_enable, set_pwm##offset##_enable) \
static DEVICE_ATTR(pwm##offset##_auto_pwm_min, S_IRUGO | S_IWUSR, \
show_pwm##offset##_auto_pwm_min, set_pwm##offset##_auto_pwm_min)
pwm_control(1);
pwm_control(2);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep ;
struct i2c_client *new_client = NULL;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (i2c_is_isa_adapter(adapter)) {
/* This chip has no ISA interface */
goto exit ;
};
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit ;
};
/* 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 adm1026_{read,write}_value. */
if (!(new_client = kmalloc((sizeof(struct i2c_client)) +
sizeof(struct adm1026_data),
GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(new_client, 0, sizeof(struct i2c_client) +
sizeof(struct adm1026_data));
data = (struct adm1026_data *) (new_client + 1);
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address );
if( company = ADM1026_COMPANY_ANALOG_DEV
&& verstep = ADM1026_VERSTEP_ADM1026 ) {
kind = adm1026 ;
} else if( company = ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC ) {
dev_err(&adapter->dev, "adm1026: "
"Unrecognized stepping 0x%02x. Defaulting to "
"ADM1026.\n", verstep);
kind = adm1026 ;
} else if( (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC ) {
dev_err(&adapter->dev, "adm1026: Found version/"
"stepping 0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip ;
} else {
dev_dbg(&new_client->dev, "adm1026: Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if( kind = 0 ) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address );
}
err = 0 ;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break ;
case adm1026 :
type_name = "adm1026";
break ;
#if 0
/* Example of another adm1026 "compatible" device */
case adx1000 :
type_name = "adx1000";
memcpy( template, adx_specific, sizeof(adx_specific) );
template_next = template + CTLTBL_ADX1000 ;
break ;
#endif
default :
dev_err(&adapter->dev, "adm1026: Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT ;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = ADM1026_INIT_VRM ;
data->vid = ADM1026_INIT_VID ;
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_therm);
device_create_file(&new_client->dev, &dev_attr_temp2_therm);
device_create_file(&new_client->dev, &dev_attr_temp3_therm);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm2);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_min);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (6 preceding siblings ...)
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
9 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi Justin,
See my comments inline.
> CHANGELOG
>
> 2003-03-13 Initial development
> 2003-05-07 First Release. Includes GPIO fixup and full
> functionality.
> 2003-05-18 Minor fixups and tweaks.
> Print GPIO config after fixup.
> Adjust fan MIN if DIV changes.
> 2003-05-21 Fix printing of FAN/GPIO config
> Fix silly bug in fan_div logic
> Fix fan_min handling so that 0xff is 0 is 0xff
> 2003-05-25 Fix more silly typos...
> 2003-06-11 Change FAN_xx_REG macros to use different scaling
> Most (all?) drivers assume two pulses per rev fans
> and the old scaling was producing double the RPM's
> Thanks to Jerome Hsiao @ Arima for pointing this out.
> 2004-01-27 Remove use of temporary ID. Define addresses as a range.
> 2004-10-18 Port to kernel 2.6.X and sysfs interface.
Delete the changelog, it doesn't belong to the 2.6 driver file.
>/* Insmod parameters */
>/* Insmod parameters */
Duplicate comment.
>/* The ADM1026 registers */
>#define ADM1026_REG_CONFIG1 (0x00)
>#define CFG1_MONITOR (0x01)
>#define CFG1_INT_ENABLE (0x02)
>#define CFG1_INT_CLEAR (0x04)
>#define CFG1_AIN8_9 (0x08)
>#define CFG1_THERM_HOT (0x10)
>#define CFG1_DAC_AFC (0x20)
>#define CFG1_PWM_AFC (0x40)
>#define CFG1_RESET (0x80)
>#define ADM1026_REG_CONFIG2 (0x01)
>/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
>#define ADM1026_REG_CONFIG3 (0x07)
>#define CFG3_GPIO16_ENABLE (0x01)
>#define CFG3_CI_CLEAR (0x02)
>#define CFG3_VREF_250 (0x04)
>#define CFG3_GPIO16_DIR (0x40)
>#define CFG3_GPIO16_POL (0x80)
>#define ADM1026_REG_E2CONFIG (0x13)
>#define E2CFG_READ (0x01)
>#define E2CFG_WRITE (0x02)
>#define E2CFG_ERASE (0x04)
>#define E2CFG_ROM (0x08)
>#define E2CFG_CLK_EXT (0x80)
Please discard the surrounding parenthesis.
>static u16 REG_IN[] = {
> 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
> 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
> 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
> };
>static u16 REG_IN_MIN[] = {
> 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
> 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
> 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
> };
>static u16 REG_IN_MAX[] = {
> 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
> 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
> 0x43, 0x44, 0x45, 0x46, 0x47
> };
>#define ADM1026_REG_IN(nr) (REG_IN[(nr)])
>#define ADM1026_REG_IN_MIN(nr) (REG_IN_MIN[(nr)])
>#define ADM1026_REG_IN_MAX(nr) (REG_IN_MAX[(nr)])
The macros are useless. What about renaming the arrays to e.g.
ADM1026_REG_IN and simply use ADM1026_REG_IN[i] in the code?
>static u16 REG_TEMP[] = { 0x1f, 0x28, 0x29 };
>static u16 REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
>static u16 REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
>static u16 REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
>static u16 REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
>static u16 REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
>#define ADM1026_REG_TEMP(nr) (REG_TEMP[(nr)])
>#define ADM1026_REG_TEMP_MIN(nr) (REG_TEMP_MIN[(nr)])
>#define ADM1026_REG_TEMP_MAX(nr) (REG_TEMP_MAX[(nr)])
>#define ADM1026_REG_TEMP_TMIN(nr) (REG_TEMP_TMIN[(nr)])
>#define ADM1026_REG_TEMP_THERM(nr) (REG_TEMP_THERM[(nr)])
>#define ADM1026_REG_TEMP_OFFSET(nr) (REG_TEMP_OFFSET[(nr)])
Ditto.
>#define ADM1026_REG_FAN_DIV_0_3 (0x02)
>#define ADM1026_REG_FAN_DIV_4_7 (0x03)
>
>#define ADM1026_REG_DAC (0x04)
>#define ADM1026_REG_PWM (0x05)
>
>#define ADM1026_REG_GPIO_CFG_0_3 (0x08)
>#define ADM1026_REG_GPIO_CFG_4_7 (0x09)
>#define ADM1026_REG_GPIO_CFG_8_11 (0x0a)
>#define ADM1026_REG_GPIO_CFG_12_15 (0x0b)
>/* CFG_16 in REG_CFG3 */
>#define ADM1026_REG_GPIO_STATUS_0_7 (0x24)
>#define ADM1026_REG_GPIO_STATUS_8_15 (0x25)
>/* STATUS_16 in REG_STATUS4 */
>#define ADM1026_REG_GPIO_MASK_0_7 (0x1c)
>#define ADM1026_REG_GPIO_MASK_8_15 (0x1d)
>/* MASK_16 in REG_MASK4 */
Drop all parenthesis here as well.
>/* IN are scaled acording to built-in resistors. These are the
> * voltages corresponding to 3/4 of full scale (192 or 0xc0)
> * NOTE: The -12V input needs an additional factor to account
> * for the Vref pullup resistor.
> * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
> * = 13875 * 2.50 / 1.875 - 2500
> * = 16000
> */
>#if 1
>/* The values in this table are based on Table II, page 15 of the
> * datasheet.
> */
>static int adm1026_scaling[] = { /* .001 Volts */
> 2250, 2250, 2250, 2250, 2250, 2250,
> 1875, 1875, 1875, 1875, 3000, 3330,
> 3330, 4995, 2250, 12000, 13875
> };
>#define NEG12_OFFSET 16000
>#else
>/* The values in this table are based on the resistors in
> * Figure 5 on page 16. But the 3.3V inputs are not in
> * the figure and the values for the 5V input are wrong.
> * For 5V, I'm guessing that R2 at 55.2k is right, but
> * the total resistance should be 1400 or 1449 like the
> * other inputs. Using 1449, gives 4.922V at 192.
> */
>static int adm1026_scaling[] = { /* .001 Volts */
> 2249, 2249, 2249, 2249, 2249, 2249,
> 1875, 1875, 1875, 1875, 3329, 3329,
> 3329, 4922, 2249, 11969, 13889
> };
>#define NEG12_OFFSET 16019
>#endif
If the resistors are built-in, only one of these series is correct,
right? So, just discard the wrong one and go with the right one.
>#if 0 /* If we have extended A/D bits */
>#define INSEXT_FROM_REG(n,val,ext) (SCALE((val)*4 + (ext),192*4,\
> adm1026_scaling[n]))
>#define INS_FROM_REG(n,val) (INSEXT_FROM_REG(n,val,0))
>#else
>#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
>#endif
Same here. People are not supposed to edit the source code and recompile.
Do the right thing and discard the rest.
>#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
In 2.6 we handle bad dividers differently. Instead of defaulting to an
arbitrary value, we refuse to do the change and return an error to
userspace. See the various other drivers as an example.
>/* Temperature is reported in 1 degC increments */
>#define TEMP_TO_REG(val) (SENSORS_LIMIT((val+500)/1000,-127,127))
>#define TEMP_FROM_REG(val) (val * 1000)
>#define OFFSET_TO_REG(val) (SENSORS_LIMIT((val+500)/1000,-127,127))
>#define OFFSET_FROM_REG(val) (val * 1000)
Broken roundings for negative values in TO_REG variants.
Missing parenthesis for the FROM_REG variants.
>/* Analog output is a voltage, but it's used like a PWM
> * Seems like this should be scaled, but to be consistent
> * with other drivers, we do it this way.
> */
>#define DAC_TO_REG(val) (SENSORS_LIMIT(val,0,255))
>#define DAC_FROM_REG(val) (val)
Analog output should be a voltage value in mV, just like analog inputs.
>/* sensors_vid.h defines vid_from_reg() */
>#define VID_FROM_REG(val,vrm) (vid_from_reg(val,vrm))
What a totally useless macro!
>/* Unlike some other drivers we DO NOT set initial limits. Use
> * the config file to set limits.
> */
Discard that comment, since all other driver have been changed and do not
set limits either.
>/* Typically used with systems using a v9.1 VRM spec ? */
>#define ADM1026_INIT_VRM 91
>#define ADM1026_INIT_VID -1
Rudolf Marek introduced a new VRM detection mechanism recently. It picks
the correct VRM version from the CPU, so the driver don't have to deal
with that. See any driver with VID support (except lm78) from 2.6.9-rc1
or above (I think) for an example.
>struct pwm_data {
> u8 pwm;
> u8 enable;
> u8 auto_pwm_min;
>};
Any special reason why pwm has a special structure?
>struct adm1026_data {
> struct semaphore lock;
> enum chips type;
>
> struct semaphore update_lock;
> int valid; /* !=0 if following fields are valid */
> unsigned long last_reading; /* In jiffies */
> unsigned long last_config; /* In jiffies */
>
> u8 in[17]; /* Register value */
> u8 in_max[17]; /* Register value */
> u8 in_min[17]; /* Register value */
> s8 temp[3]; /* Register value */
> s8 temp_min[3]; /* Register value */
> s8 temp_max[3]; /* Register value */
> s8 temp_tmin[3]; /* Register value */
> s8 temp_therm[3]; /* Register value */
> s8 temp_offset[3]; /* Register value */
> u8 fan[8]; /* Register value */
> u8 fan_min[8]; /* Register value */
> u8 fan_div[8]; /* Decoded value */
> struct pwm_data pwm[2]; /* Pwm control values */
> int vid; /* Decoded value */
> u8 vrm; /* VRM version */
> long alarms; /* Register encoding, combined */
> long alarm_mask; /* Register encoding, combined */
> long gpio; /* Register encoding, combined */
> long gpio_mask; /* Register encoding, combined */
> u8 gpio_config[17]; /* Decoded value */
> u8 config1; /* Register value */
> u8 config2; /* Register value */
> u8 config3; /* Register value */
>};
There should be an i2c_client member in there, see other chip drivers.
>static struct i2c_driver adm1026_driver = {
> .owner = THIS_MODULE,
> .name = "adm1026",
>/* .id = I2C_DRIVERID_ADM1026, */
> .flags = I2C_DF_NOTIFY,
> .attach_adapter = adm1026_attach_adapter,
> .detach_client = adm1026_detach_client,
>};
Don't include the .id line at all.
>/* Unique ID assigned to each ADM1026 detected */
>static int adm1026_id = 0;
Don't explicitely initialize it to 0, the compiler will do.
>int adm1026_attach_adapter(struct i2c_adapter *adapter)
>{
> if (!(adapter->class & I2C_ADAP_CLASS_SMBUS)) {
> return 0;
Indentation issue here.
>void adm1026_init_client(struct i2c_client *client)
>{
> int value, i;
> struct adm1026_data *data = i2c_get_clientdata(client);
>
> dev_dbg(&client->dev, "adm1026(%d): Initializing device\n",
> client->id);
dev_dbg will already print "adm1026" in front of the line if I'm not
mistaking, so you shouldn't repeat it.
> /* If the user asks us to reprogram the GPIO config, then
> * do it now. But only if this is the first ADM1026.
> */
> if( client->id = 0
Why is the first client special? You don't even know which one will be
picked first by the core.
> for( i = 0 ; i <= 7 ; ++i ) {
BTW, watch your coding style. No white space inside parenthesis, white
space betweem keywork and opening parenthesis, no white space before
semicolon: for (i = 0; i <= 7; ++i).
> /* We don't know where or even _if_ the VID might be on the GPIO
> * pins. But the datasheet gives an example config showing
> * GPIO11-15 being used to monitor VID0-4, so we go with that
> * but make the vid WRITEABLE so if it's wrong, the user can
> * set it in /etc/sensors.conf perhaps using an expression or
> * 0 to trigger a re-read from the GPIO pins.
> */
Doesn't make much sense to me. If the vid reading isnt't correct (which
can happen with any chip if the pins are not provided) then the user can
simply not use in in the configuration file at all. Making it writable
means that the user-space writes it to kernel-space just in order to
read it again for configuring the chip. Since the vid value is only
really used by "sensors -s", hardcoding it into the configuration file
is easier and more efficiemt.
>static ssize_t show_in(struct device *dev, char *buf, int nr)
>{
> struct adm1026_data *data = adm1026_update_device(dev);
> if (nr = 16) {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) -
> NEG12_OFFSET );
> } else {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) );
> }
>}
>static ssize_t show_in_min(struct device *dev, char *buf, int nr)
>{
> struct adm1026_data *data = adm1026_update_device(dev);
> if (nr = 16) {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr])
> - NEG12_OFFSET );
> } else {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr,
> data->in_min[nr])); }
>}
>static ssize_t set_in_min(struct device *dev, const char *buf,
> size_t count, int nr)
>{
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> if (nr = 16) {
> data->in_min[nr] = INS_TO_REG(nr, val + NEG12_OFFSET);
> } else {
> data->in_min[nr] = INS_TO_REG(nr, val);
> }
> adm1026_write_value(client, ADM1026_REG_IN_MIN(nr), data->in_min[nr]);
> up(&data->update_lock);
> return count;
>}
>
>static ssize_t show_in_max(struct device *dev, char *buf, int nr)
>{
> struct adm1026_data *data = adm1026_update_device(dev);
> if (nr = 16) {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr])
> - NEG12_OFFSET );
> } else {
> return sprintf(buf,"%d\n", INS_FROM_REG(nr,
> data->in_max[nr]));
> }
>}
>static ssize_t set_in_max(struct device *dev, const char *buf,
> size_t count, int nr)
>{
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> if (nr = 16) {
> data->in_max[nr] = INS_TO_REG(nr, val+NEG12_OFFSET);
> } else {
> data->in_max[nr] = INS_TO_REG(nr, val);
> }
> adm1026_write_value(client, ADM1026_REG_IN_MAX(nr), data->in_max[nr]);
> up(&data->update_lock);
> return count;
>}
Write specific callback functions for -12V since it is specific.
>static ssize_t set_fan_min(struct device *dev, const char *buf,
> size_t count, int nr)
>{
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
> adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
> data->fan_min[nr]);
> up(&data->update_lock);
> return count;
>}
I see no reason to use the update_lock semaphore here. Other I2C client
drivers don't.
>/* static ssize_t show_analog_out_reg(struct device *dev, char *buf)
>{
> struct adm1026_data *data = adm1026_update_device(dev);
> return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out) );
>}
>static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
> size_t count)
>{
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->analog_out = DAC_TO_REG(val);
> adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
> up(&data->update_lock);
> return count;
>}
>
>static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
> set_analog_out_reg)
>
>*/
Why is that part commented out?
>int adm1026_detect(struct i2c_adapter *adapter, int address,
> int kind)
>{
> (...)
> if (i2c_is_isa_adapter(adapter)) {
> /* This chip has no ISA interface */
> goto exit ;
> };
Discard that test, it's useless
> if (!(new_client = kmalloc((sizeof(struct i2c_client)) +
> sizeof(struct adm1026_data),
> GFP_KERNEL))) {
> err = -ENOMEM;
> goto exit;
> }
>
> memset(new_client, 0, sizeof(struct i2c_client) +
> sizeof(struct adm1026_data));
> data = (struct adm1026_data *) (new_client + 1);
This memory allocation scheme is outdated. I'm surprised that the code
you started from has that, since all driver in CVS and 2.6 are supposed
to be fixed for a couple months now. See in the other drivers how it is
done now.
>#if 0
> /* Example of another adm1026 "compatible" device */
> case adx1000 :
> type_name = "adx1000";
> memcpy( template, adx_specific, sizeof(adx_specific) );
> template_next = template + CTLTBL_ADX1000 ;
> break ;
>#endif
That code wouldn't work in 2.6 I guess, looks like a legacy from the 2.4
driver; discard.
> /* Set the VRM version */
> data->vrm = ADM1026_INIT_VRM ;
> data->vid = ADM1026_INIT_VID ;
Use Rudolf Marek's functions instead.
> device_create_file(&new_client->dev, &dev_attr_temp1_offset);
> device_create_file(&new_client->dev, &dev_attr_temp2_offset);
> device_create_file(&new_client->dev, &dev_attr_temp3_offset);
These are not standardized in the sysfs interface yet. It seems that
several chips have that functionality though, so it could be fine to
introduce it. Please propose a patch against
Documentation/i2c/sysfs-interface if you use these.
> device_create_file(&new_client->dev, &dev_attr_temp1_therm);
> device_create_file(&new_client->dev, &dev_attr_temp2_therm);
> device_create_file(&new_client->dev, &dev_attr_temp3_therm);
What are these files for?
I have admittedly skipped through most of the sysfs callback functions
code, since I don't have enough time to fully review this part.
Please provide patches for the CVS/2.4 driver when changes you do to the
2.6 driver would be welcome there too.
Thanks,
Jean Delvare
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (5 preceding siblings ...)
2005-05-19 6:25 ` Mark M. Hoffman
@ 2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
` (2 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi Jean,
Excellent. Thanks for the feedback!
Most everything looks straightforward. Assume that the parts of your
recommendations that I've cut out have already been applied.
I can already see that I should have done less cut 'N' pasting from the 2.4.X
driver code.
On Tue, Oct 19, 2004 at 12:09:43PM +0200, Jean Delvare wrote:
<snip>
> >/* Analog output is a voltage, but it's used like a PWM
> > * Seems like this should be scaled, but to be consistent
> > * with other drivers, we do it this way.
> > */
> >#define DAC_TO_REG(val) (SENSORS_LIMIT(val,0,255))
> >#define DAC_FROM_REG(val) (val)
>
> Analog output should be a voltage value in mV, just like analog inputs.
Ok, technically, that should be true. But you'll notice in the code I
submitted this is just a vestigal macro, and should have been cleared out
along with a lot of other cruft...
In the board I have access to(Arima HDAMA), the DAC is only used as one of two
possible means to drive the speed-controlled fans. Essentially it doesn't look
any different to the end user than the PWM output. I've chosen to expose it
as the set of sysfs files:
pwm2
pwm2_enable
pwm2_auto_pwm_min
And allow the user to choose which "pwm" drives the fans, as only one is
allowed control at a time. In line with this decision, I intend to keep
the visible value for the DAC (pwm2) on the same scale as pwm1 (0-255).
> >/* Typically used with systems using a v9.1 VRM spec ? */
> >#define ADM1026_INIT_VRM 91
> >#define ADM1026_INIT_VID -1
>
> Rudolf Marek introduced a new VRM detection mechanism recently. It picks
> the correct VRM version from the CPU, so the driver don't have to deal
> with that. See any driver with VID support (except lm78) from 2.6.9-rc1
> or above (I think) for an example.
>
> >struct pwm_data {
> > u8 pwm;
> > u8 enable;
> > u8 auto_pwm_min;
> >};
>
> Any special reason why pwm has a special structure?
*note that both pwm1_* corresponds to the actual PWM output, and pwm2_*
is really the DAC output, which for our purposes may as well be treated
identically, and is therefore lumped in with the PWM output to avoid end-user
confusion.*
I introduced pwm[12]_enable and pwm[12]_auto_pwm_min. These don't correspond
directly to register entries, but do provide automatic fan control
functionality in line with that outlined in the 1st-4th fan control interface
proposals. Because the minimum value for pwm with automatic fan control is
taken from the 4 MSB of the PWM register, I elected to provide a separate
sysfs entry that allows the selection, storage, and retention of minimum
pwm value indendent of changes in the PWM register.
The PWM interface is designed to avoid inadvertent overheating situations.
(1) PWM values cannot be changed directly unless manual control (pwmN_enable
= 1) is set.
(2) pwmN_auto_pwm_min values initialize at their maximum value of 15.
(3) pwmN_auto_pwm_min values can be changed at any time, but are not applied
until/unless the corresponding pwmN_enable = 2 (automatic fan control mode)
(4) Switching modes from automatic->manual, automatic->off, manual->off
results in the corresponding pwmN being set to its maximum value of 255.
I just decided that a pwm structure would help keep things tidy variable-
wise and enforce the association of pwmN with pwmN_enable and
pwmN_auto_pwm_min, making the code more easily parseable for other people
besides myself.
Is there any reason *not* to do this?
> >void adm1026_init_client(struct i2c_client *client)
> >{
> >int value, i;
> >struct adm1026_data *data = i2c_get_clientdata(client);
> >
> >dev_dbg(&client->dev, "adm1026(%d): Initializing device\n",
> >client->id);
>
>dev_dbg will already print "adm1026" in front of the line if I'm not
>mistaking, so you shouldn't repeat it.
It also looks like it prints out the bus id string, so I can drop "(%d)" as
well. Right?
> > /* If the user asks us to reprogram the GPIO config, then
> > * do it now. But only if this is the first ADM1026.
> > */
> > if( client->id = 0
>
> Why is the first client special? You don't even know which one will be
> picked first by the core.
You know, I'm not sure why. This is one of the bits just pasted in from the
2.4.X driver. Phil Pokorny ought to weigh in here with his reasoning.
> > for( i = 0 ; i <= 7 ; ++i ) {
>
> BTW, watch your coding style. No white space inside parenthesis, white
> space betweem keywork and opening parenthesis, no white space before
> semicolon: for (i = 0; i <= 7; ++i).
Heh. That's what I get for copying code without really reviewing it. I'll
make a pass through the code to fix these and standardize spacing conventions
between the inherited code and my own bits.
> > /* We don't know where or even _if_ the VID might be on the GPIO
> > * pins. But the datasheet gives an example config showing
> > * GPIO11-15 being used to monitor VID0-4, so we go with that
> > * but make the vid WRITEABLE so if it's wrong, the user can
> > * set it in /etc/sensors.conf perhaps using an expression or
> > * 0 to trigger a re-read from the GPIO pins.
> > */
>
> Doesn't make much sense to me. If the vid reading isnt't correct (which
> can happen with any chip if the pins are not provided) then the user can
> simply not use in in the configuration file at all. Making it writable
> means that the user-space writes it to kernel-space just in order to
> read it again for configuring the chip. Since the vid value is only
> really used by "sensors -s", hardcoding it into the configuration file
> is easier and more efficiemt.
Again, Phil Pokorny ought to weigh in on this, as it's not my original work,
nor has my perusal of the data sheet given me any particular insight as to
why the code is set up this way.
<snip>
> >static ssize_t set_fan_min(struct device *dev, const char *buf,
> > size_t count, int nr)
> >{
> > struct i2c_client *client = to_i2c_client(dev);
> > struct adm1026_data *data = i2c_get_clientdata(client);
> > int val;
> >
> > down(&data->update_lock);
> > val = simple_strtol(buf, NULL, 10);
> > data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
> > adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
> > data->fan_min[nr]);
> > up(&data->update_lock);
> > return count;
> >}
>
> I see no reason to use the update_lock semaphore here. Other I2C client
> drivers don't.
I started reviewing the other drivers, and noticed that several of them
embedded the use of the update_lock semaphore in their "XXXX_write_value"
functions as opposed to the "set_XXX" functions. I admit to blindly following
observed behavior here. Can you enlighten me on the subject? It looks as
if the other drivers still use update_lock...
> >/* static ssize_t show_analog_out_reg(struct device *dev, char *buf)
> >{
> > struct adm1026_data *data = adm1026_update_device(dev);
> > return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out) );
> >}
> >static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
> > size_t count)
> >{
> > struct i2c_client *client = to_i2c_client(dev);
> > struct adm1026_data *data = i2c_get_clientdata(client);
> > int val;
> >
> > down(&data->update_lock);
> > val = simple_strtol(buf, NULL, 10);
> > data->analog_out = DAC_TO_REG(val);
> > adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
> > up(&data->update_lock);
> > return count;
> >}
> >
> >static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
> > set_analog_out_reg)
> >
> >*/
>
> Why is that part commented out?
Because it's associated with the transmogrification of the DAC output into
"pwm2". I should have X-ed it out of the code before I sent it to you.
<snip>
>
> > /* Set the VRM version */
> > data->vrm = ADM1026_INIT_VRM ;
> > data->vid = ADM1026_INIT_VID ;
>
> Use Rudolf Marek's functions instead.
Already fixed the assignment for data->vrm.
Unless Phil weighs in with a good reason why we should leave the VID setup
as it is, I'll change this be in line with how it's done in the other drivers.
> > device_create_file(&new_client->dev, &dev_attr_temp1_offset);
> > device_create_file(&new_client->dev, &dev_attr_temp2_offset);
> > device_create_file(&new_client->dev, &dev_attr_temp3_offset);
>
> These are not standardized in the sysfs interface yet. It seems that
> several chips have that functionality though, so it could be fine to
> introduce it. Please propose a patch against
> Documentation/i2c/sysfs-interface if you use these.
Ok.
> > device_create_file(&new_client->dev, &dev_attr_temp1_therm);
> > device_create_file(&new_client->dev, &dev_attr_temp2_therm);
> > device_create_file(&new_client->dev, &dev_attr_temp3_therm);
>
> What are these files for?
Fooey. I left these in from the 2.4.X driver, and never noticed that there
needed to be a way presented to turn the "therm" function on. My fault for
assuming that the old driver was had the complete set of necessary files.
I just added:
temp_therm_enable (values {0,1})
to the list of sysfs files and the associated:
show_temp_therm_enable();
set_temp_therm_enable();
functions.
The adm1026 has a set of 3 registers (one for each temperature channel) that
allow for a "maximum failsafe" temperature to be set. As you might guess,
when any one of the temperatures reaches its respective therm value, an
interrupt is generated, and all fans go to full speed. This operates
independently of the temperature-moderated fan control.
Because it operates independently of the automatic fan control, it seems
improper to lump it in with the "tempN_auto_pointM_temp" group. Were I to
do so, and create "temp[123]_auto_point3_temp", then when automatic fan
control was enabled, there would be TWO distinct points at which the fans
would be expected to go to full speed.
(1) temp[123]_auto_point2_temp, which is fixed internally by the chip at
temp[123]_auto_point1_temp + 20 degrees C
(2) temp[123]_auto_point3_temp (AKA, temp[123]_therm)
This looks obnoxiously confusing. Moreover, it obscures the reason for the
existence of tempN_therm, which is to provide a guaranteed failsafe "keep-
the-magic-smoke-in-the-system" mechanism, no matter whether the PWM/DAC
output is being manually or automatically controlled.
> I have admittedly skipped through most of the sysfs callback functions
> code, since I don't have enough time to fully review this part.
>
> Please provide patches for the CVS/2.4 driver when changes you do to the
> 2.6 driver would be welcome there too.
Ok.
Thanks again for the feedback!
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (3 preceding siblings ...)
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Mark M. Hoffman
` (4 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
> I can already see that I should have done less cut 'N' pasting from
> the 2.4.X driver code.
This is a common "mistake" when porting the drivers. Most of the old
code in the lm_sensors project has known weaknesses and we try to clean
up everything we can on the way to 2.6.
> In the board I have access to(Arima HDAMA), the DAC is only used as
> one of two possible means to drive the speed-controlled fans.
> Essentially it doesn't look any different to the end user than the PWM
> output. I've chosen to expose it as the set of sysfs files:
>
> pwm2
> pwm2_enable
> pwm2_auto_pwm_min
>
> And allow the user to choose which "pwm" drives the fans, as only one
> is allowed control at a time. In line with this decision, I intend to
> keep the visible value for the DAC (pwm2) on the same scale as pwm1
> (0-255).
That's an interesting approach, although different from what I did for
the lm87 driver.
One possible issue is that we support monitoring chips, not
motherboards. What if the DAC is used for something different on another
motherboard? This probably has yet to be seen though.
You may have hit a problem of our sysfs interface. The pwm* files should
probably have been named with a more neutral name, with the focus on the
function rather than the technical details. That would have hidden the
method (PWM or DAC) to the user, which may have been better (or not).
I have no strong objection to "faking" the DAC as a PWM output if it
makes everybody happy. This will have to be clearly documented in the
source code and/or the extra doc files though.
BTW, how are pwm1 and pwm2 (aka DAC) linked? if pwm1 and pwm2 correspond
to the same output, shouldn't they be a single pwm file?
> (2) pwmN_auto_pwm_min values initialize at their maximum value of 15.
Should be scaled so that this max value matches the max pwm value
(around 250).
> I just decided that a pwm structure would help keep things tidy
> variable- wise and enforce the association of pwmN with pwmN_enable
> and pwmN_auto_pwm_min, making the code more easily parseable for other
> people besides myself.
>
> Is there any reason *not* to do this?
No, I was simply curious.
> >dev_dbg will already print "adm1026" in front of the line if I'm not
> >mistaking, so you shouldn't repeat it.
>
> It also looks like it prints out the bus id string, so I can drop
> "(%d)" as well. Right?
It's a different id. dev_dbg prints the bus id, while the %d is the chip
id (which is only really needed if you have more than one adm1026 chip
on the system). Other drivers don't print the chip id as far as I
remember, but if you want to keep it, feel free to do.
> > >static ssize_t set_fan_min(struct device *dev, const char *buf,
> > > size_t count, int nr)
> > >{
> > > struct i2c_client *client = to_i2c_client(dev);
> > > struct adm1026_data *data = i2c_get_clientdata(client);
> > > int val;
> > >
> > > down(&data->update_lock);
> > > val = simple_strtol(buf, NULL, 10);
> > > data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
> > > adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
> > > data->fan_min[nr]);
> > > up(&data->update_lock);
> > > return count;
> > >}
> >
> > I see no reason to use the update_lock semaphore here. Other I2C
> > client drivers don't.
>
> I started reviewing the other drivers, and noticed that several of
> them embedded the use of the update_lock semaphore in their
> "XXXX_write_value" functions as opposed to the "set_XXX" functions. I
> admit to blindly following observed behavior here. Can you enlighten
> me on the subject? It looks as if the other drivers still use
> update_lock...
Well, both ways are similar except that if put it the write funtion the
code isn't duplicated. However this prevents the use of the write
function from the update function, since it already holds a lock on the
semaphore.
In most cases I don't see why a lock is needed at all at this point. If
there is a concurent read or write, even to the same register, I don't
see how the use of a lock will change the outcome. However, the lock
shouldn't hurt either, so if you feel better with it, I have no strong
objection.
> > > device_create_file(&new_client->dev, &dev_attr_temp1_therm);
> > > device_create_file(&new_client->dev, &dev_attr_temp2_therm);
> > > device_create_file(&new_client->dev, &dev_attr_temp3_therm);
> >
> > What are these files for?
>
> Fooey. I left these in from the 2.4.X driver, and never noticed that
> there needed to be a way presented to turn the "therm" function on.
> My fault for assuming that the old driver was had the complete set of
> necessary files.
>
> I just added:
>
> temp_therm_enable (values {0,1})
>
> to the list of sysfs files and the associated:
>
> show_temp_therm_enable();
> set_temp_therm_enable();
>
> functions.
>
> The adm1026 has a set of 3 registers (one for each temperature
> channel) that allow for a "maximum failsafe" temperature to be set.
> As you might guess, when any one of the temperatures reaches its
> respective therm value, an interrupt is generated, and all fans go to
> full speed. This operates independently of the temperature-moderated
> fan control.
>
> Because it operates independently of the automatic fan control, it
> seems improper to lump it in with the "tempN_auto_pointM_temp" group.
> Were I to do so, and create "temp[123]_auto_point3_temp", then when
> automatic fan control was enabled, there would be TWO distinct points
> at which the fans would be expected to go to full speed.
>
> (1) temp[123]_auto_point2_temp, which is fixed internally by the chip
> at
> temp[123]_auto_point1_temp + 20 degrees C
> (2) temp[123]_auto_point3_temp (AKA, temp[123]_therm)
>
> This looks obnoxiously confusing. Moreover, it obscures the reason
> for the existence of tempN_therm, which is to provide a guaranteed
> failsafe "keep- the-magic-smoke-in-the-system" mechanism, no matter
> whether the PWM/DAC output is being manually or automatically
> controlled.
Agreed that it doesn't fit well in the auto-pwm logic.
I think I would simply call these entries temp[123]_crit. It's common
that chips do take actions when critical limits are crossed.
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (4 preceding siblings ...)
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Mark M. Hoffman
2005-05-19 6:25 ` Justin Thiessen
` (3 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Mark M. Hoffman @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi guys:
> >static ssize_t set_fan_min(struct device *dev, const char *buf,
> > size_t count, int nr)
> >{
> > struct i2c_client *client = to_i2c_client(dev);
> > struct adm1026_data *data = i2c_get_clientdata(client);
> > int val;
> >
> > down(&data->update_lock);
> > val = simple_strtol(buf, NULL, 10);
> > data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
> > adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
> > data->fan_min[nr]);
> > up(&data->update_lock);
> > return count;
> >}
* Jean Delvare <khali@linux-fr.org> [2004-10-19 12:09:43 +0200]:
> I see no reason to use the update_lock semaphore here. Other I2C client
> drivers don't.
This particular function does need the lock: it prevents a race condition
between data->fan_min[n] and data->fan_div[n]. I.e. the two lines starting
with the one containing FAN_TO_REG must occur atomically w.r.t. the client
data structure.
Other drivers may not need it, *iff* they do *not* adjust the fan min/max
during the set_fan_div function. This module does make that adjustment.
I think Phil P. was the first to add this code actually, and it was
something I copied into a couple other drivers (lm78 and asb100 I think).
Regards,
--
Mark M. Hoffman
mhoffman@lightlink.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (7 preceding siblings ...)
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
9 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi Mark,
>> >static ssize_t set_fan_min(struct device *dev, const char *buf,
>> > size_t count, int nr)
>> >{
>> > struct i2c_client *client = to_i2c_client(dev);
>> > struct adm1026_data *data = i2c_get_clientdata(client);
>> > int val;
>> >
>> > down(&data->update_lock);
>> > val = simple_strtol(buf, NULL, 10);
>> > data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
>> > adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
>> > data->fan_min[nr]);
>> > up(&data->update_lock);
>> > return count;
>> >}
>
>* Jean Delvare <khali@linux-fr.org> [2004-10-19 12:09:43 +0200]:
>> I see no reason to use the update_lock semaphore here. Other I2C client
>> drivers don't.
>
>This particular function does need the lock: it prevents a race condition
>between data->fan_min[n] and data->fan_div[n]. I.e. the two lines starting
>with the one containing FAN_TO_REG must occur atomically w.r.t. the client
>data structure.
>
>Other drivers may not need it, *iff* they do *not* adjust the fan min/max
>during the set_fan_div function. This module does make that adjustment.
>
>I think Phil P. was the first to add this code actually, and it was
>something I copied into a couple other drivers (lm78 and asb100 I think).
You're completely right here of course, thanks a lot for pointing my
overlooking out. What I really meant is that I don't see no reason for
locking in the general case (simply writing a voltage limit or something
like that). In the case of the fan divider this is admittedly quite
different and locking is needed.
This answers Justin's question as to where the locking should happen,
sysfs callback function or bus write function. It better be the former
so that only functions actually requiring the lock will use it.
Thanks,
Jean
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (8 preceding siblings ...)
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
9 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
On Thu, Oct 21, 2004 at 11:29:59PM +0200, Jean Delvare wrote:
Thanks again for the input!
<snip>
> > In the board I have access to(Arima HDAMA), the DAC is only used as
> > one of two possible means to drive the speed-controlled fans.
> > Essentially it doesn't look any different to the end user than the PWM
> > output. I've chosen to expose it as the set of sysfs files:
> >
> > pwm2
> > pwm2_enable
> > pwm2_auto_pwm_min
> >
> > And allow the user to choose which "pwm" drives the fans, as only one
> > is allowed control at a time. In line with this decision, I intend to
> > keep the visible value for the DAC (pwm2) on the same scale as pwm1
> > (0-255).
>
> That's an interesting approach, although different from what I did for
> the lm87 driver.
>
> One possible issue is that we support monitoring chips, not
> motherboards. What if the DAC is used for something different on another
> motherboard? This probably has yet to be seen though.
True. If an example is found where the DAC is used for something other
than driving fans, then this would need to be changed. The consequences
of providing a "fan" interface to something completely different might be
a bit ugly.
> I have no strong objection to "faking" the DAC as a PWM output if it
> makes everybody happy. This will have to be clearly documented in the
> source code and/or the extra doc files though.
I have to confess to wondering if there is any real reason to include support
for driving the fans via both the PWM and DAC. I did so because support was
already implemented in the 2.4.X kernel driver, and I decided to "fake" the
DAC as a PWM output because I could not see any significant difference between
the 2 interfaces. The driving equations are a bit different:
PWM_min = 6.67 * PWM_min_bit_value, PWM_min_bit_value in {0-15}
T_actual - T_min
PWM = PWM_min + (100 - PWM_min) * ----------------
20
vs.
DAC_min = 16 * DAC_min_bit_value, DAC_min_bit_value in {0-15}
T_actual - T_min
DAC = DAC_min + (240 - DAC_min) * ----------------
20
And you can see that the DAC output increases linearly up to 240 rather than
its full scale of 255. Per the spec, however, once the temperature increases
past tempN_auto_point1_temp, DAC jumps to its maximum value (255 => 2.5 volts).
Also note that the automatic PWM equation produces output in the range {0-100},
corresponding to % of the PWM duty cycle.
Aside from the possibility that some fans might behave in a more desireable
manner when driven by the DAC instead of the PWM output, I see no real reason to
provide both sets of interfaces to the user.
Unfortunately then, I'm not sure that there is ANY reason to include support
for the DAC in the driver. If all the DAC is used for on known boards is to
essentially duplicate the function of the PWM, then what does providing
a driver interface for it gain the end-user, aside from probable confusion
over which fan-control mechanism to use? Sure, I could leave in the
"analog_out" device files and remove the ability to enable the DAC as the
driving output for fan control, but then we have what is a basicly useless
device file littering the sysfs interface.
> BTW, how are pwm1 and pwm2 (aka DAC) linked? if pwm1 and pwm2 correspond
> to the same output, shouldn't they be a single pwm file?
You can have one or the other, but not both. And since all PWM/DAC-controlled
fans are driven by no more than one output at a time, providing access to
both seems even less useful.
But I see your point. If we keep the DAC output as well as the PWM output
in the interface, there really is no reason to provide separate pwm1_* and
pwm2_* entries, since only one can operate at a time. Then we would need to
replace
pwm[1-2]_enable, {0,1,2}
with a single file such as:
pwm_enable, {0,1,2,3,4}
where:
0 -> no fan control, fans set @ full speed
1 -> manual PWM fan control
2 -> manual DAC fan control
3 -> automatic PWM fan control
4 -> automatic DAC fan control
> > (2) pwmN_auto_pwm_min values initialize at their maximum value of 15.
>
> Should be scaled so that this max value matches the max pwm value
> (around 250).
Ugh. Is this really a good idea? Is scaling pwnN_auto_pwm_min so that it
matches pwmN worth:
(A) Obscuring the actual granularity of pwmN_auto_pwm_min
(B) Introducing "best fit" functions/macros to scale {0-255} => {0-15}.
Especially since the PWM := PWM(PWM_min) equation actually just generates
values in the {0-100} range. Which granularity level should we respect?
{0-255}? {0-100}? {0-15}?
Is pwmN_auto_pwm_min using a different scale than pwmN any more confusing
when compared to the effect that the "invisible" granularity a
pwmN_auto_pwm_min scaled {0-255} or {0-100} will have?
Moreover, if we are to keep the DAC as a 2nd "PWM" output, then shouldn't its
pwmN_auto_pwm_min scale {0-240}, rather than {0-255}?
> > I just decided that a pwm structure would help keep things tidy
> > variable- wise and enforce the association of pwmN with pwmN_enable
> > and pwmN_auto_pwm_min, making the code more easily parseable for other
> > people besides myself.
> >
> > Is there any reason *not* to do this?
>
> No, I was simply curious.
I may be lazy, but I like things tidy. ;)
> > > > device_create_file(&new_client->dev, &dev_attr_temp1_therm);
> > > > device_create_file(&new_client->dev, &dev_attr_temp2_therm);
> > > > device_create_file(&new_client->dev, &dev_attr_temp3_therm);
<snip>
> Agreed that it doesn't fit well in the auto-pwm logic.
>
> I think I would simply call these entries temp[123]_crit. It's common
> that chips do take actions when critical limits are crossed.
Will do. Thanks for the suggestion.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
` (6 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
> > BTW, how are pwm1 and pwm2 (aka DAC) linked? if pwm1 and pwm2
> > correspond to the same output, shouldn't they be a single pwm file?
>
> You can have one or the other, but not both. And since all
> PWM/DAC-controlled fans are driven by no more than one output at a
> time, providing access to both seems even less useful.
This convinces me that we need a single pwm file then.
> But I see your point. If we keep the DAC output as well as the PWM
> output in the interface, there really is no reason to provide separate
> pwm1_* and pwm2_* entries, since only one can operate at a time. Then
> we would need to replace
>
> pwm[1-2]_enable, {0,1,2}
>
> with a single file such as:
>
> pwm_enable, {0,1,2,3,4}
>
> where:
>
> 0 -> no fan control, fans set @ full speed
> 1 -> manual PWM fan control
> 2 -> manual DAC fan control
> 3 -> automatic PWM fan control
> 4 -> automatic DAC fan control
This won't be allowed since value 2 is standardized as auto mode. You
could default to PWM and allow the used to switch to DAC, or provide a
non-standard file to switch from PWM to DAC and back (pwm1_mode?)
> > Should be scaled so that this max value matches the max pwm value
> > (around 250).
>
> Ugh. Is this really a good idea? Is scaling pwnN_auto_pwm_min so
> that it matches pwmN worth:
>
> (A) Obscuring the actual granularity of pwmN_auto_pwm_min
We don't much care about the granularity. All measured values are
reported in a fixed unit (mV...) regardless of the chip. This is the
only way to provide a unified interface where the user (or user-space
application) doesn't need to know anything about the chip.
The granularity issue and the rounding errors are really not a problem.
Noone can differenciate between 80% and 82% duty cycle anyway.
The ultimate goal is that the user can echo 192 to the pwm file and get
around 75% duty cycle regardless of the chip.
> (B) Introducing "best fit" functions/macros to scale {0-255} =>
> {0-15}.
Converting from 0-15 to 0-255 is easy and lossless (X << 4 + X, X >> 4).
> Especially since the PWM := PWM(PWM_min) equation actually just
> generates values in the {0-100} range. Which granularity level should
> we respect?{0-255}? {0-100}? {0-15}?
0-255. Think standard.
> Is pwmN_auto_pwm_min using a different scale than pwmN any more
> confusing when compared to the effect that the "invisible" granularity
> a pwmN_auto_pwm_min scaled {0-255} or {0-100} will have?
pwmN_auto_* files have to be consistent with pwmN values of course.
> Moreover, if we are to keep the DAC as a 2nd "PWM" output, then
> shouldn't its pwmN_auto_pwm_min scale {0-240}, rather than {0-255}?
I admit I don't really care about 0-240 vs 0-255. I think we have
drivers doing both. Since the underlying hardware only knows of 16 steps
anyway, this doesn't make much difference. 255 is the standard though ;)
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
` (2 preceding siblings ...)
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.X Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
` (5 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
On Mon, Oct 25, 2004 at 10:39:58PM +0200, Jean Delvare wrote:
> > But I see your point. If we keep the DAC output as well as the PWM
> > output in the interface, there really is no reason to provide separate
> > pwm1_* and pwm2_* entries, since only one can operate at a time. Then
> > we would need to replace
> >
> > pwm[1-2]_enable, {0,1,2}
> >
> > with a single file such as:
> >
> > pwm_enable, {0,1,2,3,4}
> >
> > where:
> >
> > 0 -> no fan control, fans set @ full speed
> > 1 -> manual PWM fan control
> > 2 -> manual DAC fan control
> > 3 -> automatic PWM fan control
> > 4 -> automatic DAC fan control
>
> This won't be allowed since value 2 is standardized as auto mode. You
> could default to PWM and allow the used to switch to DAC, or provide a
> non-standard file to switch from PWM to DAC and back (pwm1_mode?)
Ok. Let's try this:
pwm1 {0-255} Actual PWM/DAC value, single interface to
both registers.
pwm1_auto_pwm_min {0-255} Scaled to {0-15}, single interface to both
registers.
pwm1_enable {0-2} Fan control: off, manual, and automatic,
respectively
pwm1_mode {0-1} 0 (default) is PWM control of fans, 1 is DAC.
-------
Thanks,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
` (8 subsequent siblings)
9 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
>Ok. Let's try this:
>
>pwm1 {0-255} Actual PWM/DAC value, single interface to
> both registers.
>pwm1_auto_pwm_min {0-255} Scaled to {0-15}, single interface to both
> registers.
>pwm1_enable {0-2} Fan control: off, manual, and automatic,
> respectively
>pwm1_mode {0-1} 0 (default) is PWM control of fans, 1 is
> DAC.
Fine with me. You may even rename pwm1_mode to pwm1_dac or use text
strings as the values (say "pwm" and "dac") so as to make the
interface self-explaining. Not a big deal anyway, and we obviously lack
the knowledge of other chips with similar functionality to decide what
the smartest move would be. We can always change it afterwards if such
chips arise. I don't think it'll happen though, since DAC have
completely disappeared from newer chips.
--
Jean Delvare
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.X Jean Delvare
` (7 subsequent siblings)
9 siblings, 1 reply; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
On Tue, Oct 26, 2004 at 09:49:22AM +0200, Jean Delvare wrote:
>
> >Ok. Let's try this:
> >
> >pwm1 {0-255} Actual PWM/DAC value, single interface to
> > both registers.
> >pwm1_auto_pwm_min {0-255} Scaled to {0-15}, single interface to both
> > registers.
> >pwm1_enable {0-2} Fan control: off, manual, and automatic,
> > respectively
> >pwm1_mode {0-1} 0 (default) is PWM control of fans, 1 is
> > DAC.
>
> Fine with me. You may even rename pwm1_mode to pwm1_dac or use text
> strings as the values (say "pwm" and "dac") so as to make the
> interface self-explaining. Not a big deal anyway, and we obviously lack
> the knowledge of other chips with similar functionality to decide what
> the smartest move would be. We can always change it afterwards if such
> chips arise. I don't think it'll happen though, since DAC have
> completely disappeared from newer chips.
Ah, I've been an idiot. After making these changes I went through and
tested fan control bits again.
It turns out that the DAC is not connected to *any* of the fan outputs on the
Arima HDAMA. (A fact which I have just verified by connecting fans to all
fan connectors on the motherboard, including ones listed as not being
connected to the adm1026, and writing minimum and maximum values to the
DAC register, and to the DAC fan-control enable bit.) I was sure that I had
tested DAC-only driving of the fans earlier, but apparently I had only done
so with automatic _PWM_ control of the fans enabled. Since the 4 most
significant bits of the DAC register determine BOTH minimum PWM frequency and
minimum DAC driving voltage when both PWM and DAC automatic fan control are
enabled, the fact that the DAC is not connected to the fans is camouflaged by
the continued operation of the PWM. I misinterpreted the ADM1026 docs in the
lm_sensors doc/chips directory as implying that a set of fans could be
controlled by either the PWM or the DAC, depending on how the register 00h
was set. The more likely situation is, of course, that mutually exclusive
sets of fans could be connected to PWM and the DAC outputs.
Because of this, my previous interface design is rather borked. It is
rather obviously a Bad Idea to allow the user to believe he was setting the
DAC as the output driving all the fans. Done blindly, it would result in the
fans totally failing to function on the HDAMA.
So:
(1) There is no pwm1_mode or pwm1_dac, and therefore no end-user method
provided that implies it is possible to set the DAC as the driving
output for all the fans. This was based on my faulty interpretation
of the docs, and has to go.
(2) There is now no way provided to set up automatic fan control driven by
the DAC. This encompasses the step taken in (1) but also excludes
any exposure of the bit necessary to set the DAC output into automatic
fan control mode. I have provided simple access to the DAC register,
(see (3)), but nothing else.
As noted before, when the DAC is set to automatic fan control mode, the
value in the 4 MSB of the DAC register supersedes that in the 4 MSB of
the PWM control register. It would be extremely bad form to provide
access to a "toggle" bit that does nothing in the known implementation
other than change which sysfs file must be written in order to set
minimum fan speed under automatic fan control! As for slaving the DAC
registers and sysfs files to the PWM ones, see (4)
(3) I've added the sysfs file "analog_out" which provides access to
the DAC register, and which is displayed in millivolts. At the moment,
this has no utility (AFAIK) with respect to the HDAMA board, but because
it might have some use in other applications and because it was provided
in the 2.4.X driver I have included it.
(4) The pwm* sysfs files now only change PWM-specific registers. I could
simply hard-code the set_pwm* and show_pwm* functions to write both
PWM and DAC outputs with identical values, but slaving DAC-specific
sysfs files and registers to their PWM counterparts looks like a bad
idea considering that I have no way of actually testing the results in
a system with the DAC connected.
The possible solution I see is to provide a sysfs file to allow
toggling of whether or not the DAC registers are slaved to the PWM
values. Something like:
pwm1_controls_dac {0-1}
(Even though in actuality the value in the DAC register overrides the
one in the PWM register during automatic fan control, introducing
dac_controls_pwm1 is poor design because the name implies the existence
of dac_specific sysfs files that would need to be manipulated.
dac_mirrors_pwm might be better(?))
could be added to the pwm* set of sysfs files.
pwm1 {0-255}
pwm1_auto_pwm_min {0-255}
pwm1_enable {0-1}
With sensible defaults and checks to ensure appropriate mode-change
behavior. E.g:
(A) When pwm1_controls_dac is turned on, all PWM settings are copied to
the corresponding DAC ones and applied.
(B) When pwm1_controls_dac is turned off, the fan control via the DAC
is turned off and the DAC register is set back to its maximum value.
analog_out could be preserved under this scheme, and a simple check of
pwm1_controls_dac might be used to fake changing it from RW to RO when
the DAC was slaved to the PWM registers, thus preserving the ability to
monitor the DAC's output in terms of voltage, even during DAC automatic
fan control, but obviating the possibility of changing driving voltages
to fans through more than one sysfs entry.
Opinions on (4)? I think it would work, but I'm not sure it's really worth
implementing. I'm inclined to just go back to:
pwm1
pwm1_auto_pwm_min
pwm1_enable
analog_out
I appologize for wasting everyone's time discussing this issue.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: phil; +Cc: sensors, Greg KH, khali, linux-kernel
Hi,
Here is the revised adm1026 driver port for kernel 2.6.10-rc1. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm1 {0-255}
pwm1_auto_pwm_min {0-255}
pwm1_enable {0-2} (off, manual, automatic fan control)
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {-6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) = 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id = 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min%5;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) = 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div = 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
return sprintf(buf,"%d\n",
TEMP_FROM_REG(ADM1026_FAN_ACTIVATION_TEMP_HYST));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG((data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE)));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val = 1) || (val=0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable = 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable = 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val = 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val = 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable = 1) && (val = 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm1_auto_pwm_min, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company = ADM1026_COMPANY_ANALOG_DEV
&& verstep = ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company = ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind = 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: sensors, linux-kernel, Greg KH
Hi justin,
> As discussed in previous messages, control over the pwm output is
> provided via:
>
> pwm1 {0-255}
> pwm1_auto_pwm_min {0-255}
What exactly does this value represent again? (See below too.)
> pwm1_enable {0-2} (off, manual, automatic fan control)
>
> Access to the DAC is provided via:
>
> analog_out {0-2500} (millivolts)
>
> No way is currently provided to turn on DAC-mediated automatic fan
> control. See my previous email in this thread for the reasons why.
On a side note, MBM lists the ADM1026 as being used on only two
motherboard models, one being yours. Considering this and the fact that
nobody ever requested us to port the adm1026 driver to Linux 2.6, I
would conclude that the motherboard you use is possibly the only one
worth supporting. Do not bother with anything that you don't personally
need. We can still add it later on request.
> Control over automatic fan "on" temperatures are provided by:
>
> temp[1-3]_auto_point1_temp {-128000 - 127000}
>
> Hardware-determined hysteresis and range values are revealed in:
>
> temp[1-3]_auto_point1_temp_hyst {-6000}
Hysteresis temperatures have to be absolute temperatures as per
interface standard.
> temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
I'm a bit surprised not to see temp[1-3]_auto_point[1-2]_pwm. Trip
points are supposed to be (temp, pwm) pairs. Doesn't pwm1_auto_pwm_min
above correspond to one or more of these?
> Failsafe critical temperatures at which the fans go to maximum speed
> are controled via:
>
> temp_crit_enable {0-1} (off, on)
> temp[1-3]_crit {-128000 - 127000}
Granted it's not part of the standard yet, but you would have three
files temp[1-3]_crit_enable if we stick to our chip-indenpendent
interface logic. Either make 1 read-write and [2-3] read-only, or make
all read-write and each one changes the three values.
> These values override any values set for the pwm-mediated automatic
> fan control.
Doesn't this mean that you could integrate these in the auto-pwm
interface as point3?
> Thanks to all for the feedback.
You're welcome. Sorry to ask questions about the proposed interface
again, I just want things to be as clean and logical as possible.
Thanks,
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: LM Sensors, LKML; +Cc: Greg KH
On Tue, Nov 02, 2004 at 08:31:22PM +0100, Jean Delvare wrote:
> Hi justin,
<snip>
> On a side note, MBM lists the ADM1026 as being used on only two
> motherboard models, one being yours. Considering this and the fact that
> nobody ever requested us to port the adm1026 driver to Linux 2.6, I
> would conclude that the motherboard you use is possibly the only one
> worth supporting. Do not bother with anything that you don't personally
> need. We can still add it later on request.
Ok.
> Hysteresis temperatures have to be absolute temperatures as per
> interface standard.
Ok.
> > temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
>
> I'm a bit surprised not to see temp[1-3]_auto_point[1-2]_pwm. Trip
> points are supposed to be (temp, pwm) pairs. Doesn't pwm1_auto_pwm_min
> above correspond to one or more of these?
Yes. On its way. I think it got lost somewhere in my reading of the
discussion over auto-fan interface proposals.
> > Failsafe critical temperatures at which the fans go to maximum speed
> > are controled via:
> >
> > temp_crit_enable {0-1} (off, on)
> > temp[1-3]_crit {-128000 - 127000}
>
> Granted it's not part of the standard yet, but you would have three
> files temp[1-3]_crit_enable if we stick to our chip-indenpendent
> interface logic. Either make 1 read-write and [2-3] read-only, or make
> all read-write and each one changes the three values.
Any reason not to simply provide 3 sysfs files pointing at the same variable/
register bit? Maintaining separate variables for a single, uncomplicated
value seems rather overkill.
> > These values override any values set for the pwm-mediated automatic
> > fan control.
>
> Doesn't this mean that you could integrate these in the auto-pwm
> interface as point3?
No. It is important for this to remain seperate from the auto-pwm interface.
It can be set to operate when PWM control is set to "manual", providing a
useful fail-safe mechanism, or when PWM control is set to "off" (Although
it should not be needed in the latter case, as in theory the fans are running
at full speed when PWM control is disabled.)
Moreover, integrating it into the *auto_pointN_temp heirarchy would be
ugly, as there is really only one set of values (temp[1-3]_auto_point1_temp)
that can be independently changed by the end-user.
temp[1-3]_auto_point1_temp_hyst and temp[1-3]_auto_point2_temp are fixed in
hardware at positions relative to temp[1-3]_auto_point1_temp. The function
of temp[1-3]_crit essentially overlaps that of temp[13]_auto_point2_temp
when both automatic PWM fan control and critical temperature monitoring
are enabled. Both provide temperatures at which fan speeds are ramped up
to maximum. This means integrating the temp[1-3]_crit function into the
*_auto_point?_temp heirarchy would result in 2 distinct sets of files that
determine when fan speeds are supposed to go to max.
A better way to think of it is that the temp[1-3]_crit files provide a
method for the end-user to set absolute "holy-cow-my-system-is-glowing"
temperatures at which fans MUST ramp up to full speed. It's a fail-safe
that will kick in to try and save the system's bacon in an emergency. As
it operates with or without the PWM automatic fan control, it can be employed
whether or not the end-user wants to muck about with such.
I would agree that it is a bit confusing that there are essentially 2
temperature-motivated mechanisms for forcing fan speeds to full (automatic
PWM fan control, and critical temperature monitoring), but I think that the
utility of providing a critical temperature fail-safe is worth the
minor amount of confusion.
> > Thanks to all for the feedback.
>
> You're welcome. Sorry to ask questions about the proposed interface
> again, I just want things to be as clean and logical as possible.
No problem. Sorry that it's taking so much revision to get the kinks worked
out. This will undoubtedly become less trouble as I get more familiar with
i2c/lm_sensors/kernel issues.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: jthiessen, sensors, linux-kernel; +Cc: Greg KH
Hi Justin,
> > Granted it's not part of the standard yet, but you would have three
> > files temp[1-3]_crit_enable if we stick to our chip-indenpendent
> > interface logic. Either make 1 read-write and [2-3] read-only, or make
> > all read-write and each one changes the three values.
>
> Any reason not to simply provide 3 sysfs files pointing at the same
> variable/register bit? Maintaining separate variables for a single,
> uncomplicated value seems rather overkill.
That's pretty much what I was proposing, actually ;) I never meant three
different variables. The discussion was about having all files
read-write or not. I usually have only the first file read-write and
others read-only mirrors thereof, but sometimes people don't like that
arbitrary symmetry breakage and go for read-write mirrors. You choose.
> (...)
> I would agree that it is a bit confusing that there are essentially 2
> temperature-motivated mechanisms for forcing fan speeds to full (automatic
> PWM fan control, and critical temperature monitoring), but I think that the
> utility of providing a critical temperature fail-safe is worth the
> minor amount of confusion.
Agreed.
> No problem. Sorry that it's taking so much revision to get the kinks
> worked out. This will undoubtedly become less trouble as I get more
> familiar with i2c/lm_sensors/kernel issues.
Well, the adm1026 driver is a complex driver which never received testing
and reviewing so far, because it is so rarely found on motherboards.
It's perfectly normal that it takes a couple revisions and discussion
to get it in good shape. Thanks for the good work so far.
--
Jean Delvare
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Ok, let's try this again:
Here is the revised adm1026 driver port for kernel 2.6.10-rc1. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable and simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x2c, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
#define ADM1026_PWM_MAX 255
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) = 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id = 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min%5;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) = 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div = 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(
ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val = 1) || (val=0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable = 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable = 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
{
return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val = 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val = 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable = 1) && (val = 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company = ADM1026_COMPANY_ANALOG_DEV
&& verstep = ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company = ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind = 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm2);
device_create_file(&new_client->dev, &dev_attr_pwm3);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.X - [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, sensors, linux-kernel
> Hi,
>
> Ok, let's try this again:
Fine with me. Care to send this again as a patch against 2.6.10-rc2?
This would include updates to drivers/i2c/chips/Makefile and
drivers/i2c/chips/Kconfig.
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Ok, let's try this (yet) again:
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
/*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Chip details at:
<http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
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 <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_1(adm1026);
static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1 };
static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
MODULE_PARM(gpio_input,"1-17i");
MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
MODULE_PARM(gpio_output,"1-17i");
MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
"outputs");
MODULE_PARM(gpio_inverted,"1-17i");
MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
"inverted");
MODULE_PARM(gpio_normal,"1-17i");
MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
"normal/non-inverted");
MODULE_PARM(gpio_fan,"1-8i");
MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
/* Many ADM1026 constants specified below */
/* The ADM1026 registers */
#define ADM1026_REG_CONFIG1 0x00
#define CFG1_MONITOR 0x01
#define CFG1_INT_ENABLE 0x02
#define CFG1_INT_CLEAR 0x04
#define CFG1_AIN8_9 0x08
#define CFG1_THERM_HOT 0x10
#define CFG1_DAC_AFC 0x20
#define CFG1_PWM_AFC 0x40
#define CFG1_RESET 0x80
#define ADM1026_REG_CONFIG2 0x01
/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
#define ADM1026_REG_CONFIG3 0x07
#define CFG3_GPIO16_ENABLE 0x01
#define CFG3_CI_CLEAR 0x02
#define CFG3_VREF_250 0x04
#define CFG3_GPIO16_DIR 0x40
#define CFG3_GPIO16_POL 0x80
#define ADM1026_REG_E2CONFIG 0x13
#define E2CFG_READ 0x01
#define E2CFG_WRITE 0x02
#define E2CFG_ERASE 0x04
#define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs
* They are:
* 0 - 9 = AIN0 - AIN9
* 10 = Vbat
* 11 = 3.3V Standby
* 12 = 3.3V Main
* 13 = +5V
* 14 = Vccp (CPU core voltage)
* 15 = +12V
* 16 = -12V
*/
static u16 ADM1026_REG_IN[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f
};
static u16 ADM1026_REG_IN_MIN[] = {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
0x4b, 0x4c, 0x4d, 0x4e, 0x4f
};
static u16 ADM1026_REG_IN_MAX[] = {
0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
0x43, 0x44, 0x45, 0x46, 0x47
};
/* Temperatures are:
* 0 - Internal
* 1 - External 1
* 2 - External 2
*/
static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_REG_FAN(nr) (0x38 + (nr))
#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
#define ADM1026_REG_FAN_DIV_0_3 0x02
#define ADM1026_REG_FAN_DIV_4_7 0x03
#define ADM1026_REG_DAC 0x04
#define ADM1026_REG_PWM 0x05
#define ADM1026_REG_GPIO_CFG_0_3 0x08
#define ADM1026_REG_GPIO_CFG_4_7 0x09
#define ADM1026_REG_GPIO_CFG_8_11 0x0a
#define ADM1026_REG_GPIO_CFG_12_15 0x0b
/* CFG_16 in REG_CFG3 */
#define ADM1026_REG_GPIO_STATUS_0_7 0x24
#define ADM1026_REG_GPIO_STATUS_8_15 0x25
/* STATUS_16 in REG_STATUS4 */
#define ADM1026_REG_GPIO_MASK_0_7 0x1c
#define ADM1026_REG_GPIO_MASK_8_15 0x1d
/* MASK_16 in REG_MASK4 */
#define ADM1026_REG_COMPANY 0x16
#define ADM1026_REG_VERSTEP 0x17
/* These are the recognized values for the above regs */
#define ADM1026_COMPANY_ANALOG_DEV 0x41
#define ADM1026_VERSTEP_GENERIC 0x40
#define ADM1026_VERSTEP_ADM1026 0x44
#define ADM1026_REG_MASK1 0x18
#define ADM1026_REG_MASK2 0x19
#define ADM1026_REG_MASK3 0x1a
#define ADM1026_REG_MASK4 0x1b
#define ADM1026_REG_STATUS1 0x20
#define ADM1026_REG_STATUS2 0x21
#define ADM1026_REG_STATUS3 0x22
#define ADM1026_REG_STATUS4 0x23
#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
#define ADM1026_PWM_MAX 255
/* 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.
*/
/* IN are scaled acording to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor.
* NEG12_OFFSET = SCALE * Vref / V-192 - Vref
* = 13875 * 2.50 / 1.875 - 2500
* = 16000
*
* The values in this table are based on Table II, page 15 of the
* datasheet.
*/
static int adm1026_scaling[] = { /* .001 Volts */
2250, 2250, 2250, 2250, 2250, 2250,
1875, 1875, 1875, 1875, 3000, 3330,
3330, 4995, 2250, 12000, 13875
};
#define NEG12_OFFSET 16000
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
0,255))
#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
*/
#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
(div)),1,254))
#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
(div)))
#define DIV_FROM_REG(val) (1<<(val))
#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-127,127))
#define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val)
#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
#define DAC_FROM_REG(val) (((val)*2500)/255)
/* Typically used with systems using a v9.1 VRM spec ? */
#define ADM1026_INIT_VRM 91
/* Chip sampling rates
*
* Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that.
* We cache the results and return the saved data if the driver
* is called again before a second has elapsed.
*
* Also, there is significant configuration data for this chip
* So, we keep the config data up to date in the cache
* when it is written and only sample it once every 5 *minutes*
*/
#define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system.
*
* For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */
struct pwm_data {
u8 pwm;
u8 enable;
u8 auto_pwm_min;
};
struct adm1026_data {
struct i2c_client client;
struct semaphore lock;
enum chips type;
struct semaphore update_lock;
int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */
u8 in[17]; /* Register value */
u8 in_max[17]; /* Register value */
u8 in_min[17]; /* Register value */
s8 temp[3]; /* Register value */
s8 temp_min[3]; /* Register value */
s8 temp_max[3]; /* Register value */
s8 temp_tmin[3]; /* Register value */
s8 temp_crit[3]; /* Register value */
s8 temp_offset[3]; /* Register value */
u8 fan[8]; /* Register value */
u8 fan_min[8]; /* Register value */
u8 fan_div[8]; /* Decoded value */
struct pwm_data pwm1; /* Pwm control values */
int vid; /* Decoded value */
u8 vrm; /* VRM version */
u8 analog_out; /* Register value (DAC) */
long alarms; /* Register encoding, combined */
long alarm_mask; /* Register encoding, combined */
long gpio; /* Register encoding, combined */
long gpio_mask; /* Register encoding, combined */
u8 gpio_config[17]; /* Decoded value */
u8 config1; /* Register value */
u8 config2; /* Register value */
u8 config3; /* Register value */
};
static int adm1026_attach_adapter(struct i2c_adapter *adapter);
static int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind);
static int adm1026_detach_client(struct i2c_client *client);
static int adm1026_read_value(struct i2c_client *client, u8 register);
static int adm1026_write_value(struct i2c_client *client, u8 register,
int value);
static void adm1026_print_gpio(struct i2c_client *client);
static void adm1026_fixup_gpio(struct i2c_client *client);
static struct adm1026_data *adm1026_update_device(struct device *dev);
static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
static int adm1026_id;
int adm1026_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_CLASS_HWMON)) {
return 0;
}
return i2c_detect(adapter, &addr_data, adm1026_detect);
}
int adm1026_detach_client(struct i2c_client *client)
{
i2c_detach_client(client);
kfree(client);
return 0;
}
int adm1026_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_read_byte_data(client, reg) & 0xff;
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
{
int res;
if (reg < 0x80) {
/* "RAM" locations */
res = i2c_smbus_write_byte_data(client, reg, value);
} else {
/* EEPROM, do nothing */
res = 0;
}
return res;
}
void adm1026_init_client(struct i2c_client *client)
{
int value, i;
struct adm1026_data *data = i2c_get_clientdata(client);
dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
/* Read chip config */
data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
/* Inform user of chip config */
dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
client->id, data->config1);
if ((data->config1 & CFG1_MONITOR) = 0) {
dev_dbg(&client->dev, "(%d): Monitoring not currently "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_INT_ENABLE) {
dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
"enabled.\n", client->id);
}
if (data->config1 & CFG1_AIN8_9) {
dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
"temp3 disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
"in9 disabled.\n", client->id);
}
if (data->config1 & CFG1_THERM_HOT) {
dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
"and temp limits enabled.\n", client->id);
}
value = data->config3;
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
"pin disabled.\n", client->id);
} else {
dev_dbg(&client->dev, "(%d): THERM pin enabled. "
"GPIO16 disabled.\n", client->id);
}
if (data->config3 & CFG3_VREF_250) {
dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
client->id);
} else {
dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
client->id);
}
/* Read and pick apart the existing GPIO configuration */
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
/* ... and then print it */
adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then
* do it now. But only if this is the first ADM1026.
*/
if (client->id = 0
&& (gpio_input[0] != -1 || gpio_output[0] != -1
|| gpio_inverted[0] != -1 || gpio_normal[0] != -1
|| gpio_fan[0] != -1)) {
adm1026_fixup_gpio(client);
}
/* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no
* control and will suffice until 'sensors -s'
* can be run by the user. We DO set the default
* value for pwm1.auto_pwm_min to its maximum
* so that enabling automatic pwm fan control
* without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease.
*/
data->pwm1.auto_pwm_min%5;
/* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */
value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
client->id, value);
data->config1 = value;
adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
}
void adm1026_print_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
dev_dbg(&client->dev, "(%d): GPIO config is:",
client->id);
for (i = 0;i <= 7;++i) {
if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
} else {
dev_dbg(&client->dev, "\t(%d): FAN%d\n",
client->id, i);
}
}
for (i = 8;i <= 15;++i) {
dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN",
i);
}
if (data->config3 & CFG3_GPIO16_ENABLE) {
dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
data->gpio_config[16] & 0x02 ? "" : "!",
data->gpio_config[16] & 0x01 ? "OUT" : "IN");
} else {
/* GPIO16 is THERM */
dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
}
}
void adm1026_fixup_gpio(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
int value;
/* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been
* tested much. FIXME
*/
/* Make outputs */
for (i = 0;i <= 16;++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
data->config2 |= 1 << gpio_output[i];
}
}
/* Input overrides output */
for (i = 0;i <= 16;++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
data->gpio_config[gpio_input[i]] &= ~ 0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
data->config2 |= 1 << gpio_input[i];
}
}
/* Inverted */
for (i = 0;i <= 16;++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
}
}
/* Normal overrides inverted */
for (i = 0;i <= 16;++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
data->gpio_config[gpio_normal[i]] |= 0x02;
}
}
/* Fan overrides input and output */
for (i = 0;i <= 7;++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
data->config2 &= ~(1 << gpio_fan[i]);
}
}
/* Write new configs to registers */
adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) {
value <<= 2;
value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) = 0) {
adm1026_write_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4,
value);
value = 0;
}
}
/* Print the new config */
adm1026_print_gpio(client);
}
static struct adm1026_data *adm1026_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int i;
long value, alarms, gpio;
down(&data->update_lock);
if (!data->valid
|| (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */
dev_dbg(&client->dev,"(%d): Reading sensor values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in[i] adm1026_read_value(client, ADM1026_REG_IN[i]);
}
for (i = 0;i <= 7;++i) {
data->fan[i] adm1026_read_value(client, ADM1026_REG_FAN(i));
}
for (i = 0;i <= 2;++i) {
/* NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment */
data->temp[i] adm1026_read_value(client, ADM1026_REG_TEMP[i]);
}
data->pwm1.pwm = adm1026_read_value(client,
ADM1026_REG_PWM);
data->analog_out = adm1026_read_value(client,
ADM1026_REG_DAC);
/* GPIO16 is MSbit of alarms, move it to gpio */
alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms &= 0x7f;
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
data->alarms = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_STATUS_0_7);
data->gpio = gpio;
data->last_reading = jiffies;
}; /* last_reading */
if (!data->valid || (jiffies - data->last_config >
ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */
dev_dbg(&client->dev, "(%d): Reading config values\n",
client->id);
for (i = 0;i <= 16;++i) {
data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client,
ADM1026_REG_IN_MAX[i]);
}
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8);
for (i = 0;i <= 7;++i) {
data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2;
}
for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment
*/
data->temp_min[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MIN[i]);
data->temp_max[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_MAX[i]);
data->temp_tmin[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_TMIN[i]);
data->temp_crit[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_THERM[i]);
data->temp_offset[i] = adm1026_read_value(client,
ADM1026_REG_TEMP_OFFSET[i]);
}
/* Read the STATUS/alarm masks */
alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
alarms = (alarms & 0x7f) << 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
alarms <<= 8;
alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
data->alarm_mask = alarms;
/* Read the GPIO values */
gpio |= adm1026_read_value(client,
ADM1026_REG_GPIO_MASK_8_15);
gpio <<= 8;
gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
data->gpio_mask = gpio;
/* Read various values from CONFIG1 */
data->config1 = adm1026_read_value(client,
ADM1026_REG_CONFIG1);
if (data->config1 & CFG1_PWM_AFC) {
data->pwm1.enable = 2;
data->pwm1.auto_pwm_min =
PWM_MIN_FROM_REG(data->pwm1.pwm);
}
/* Read the GPIO config */
data->config2 = adm1026_read_value(client,
ADM1026_REG_CONFIG2);
data->config3 = adm1026_read_value(client,
ADM1026_REG_CONFIG3);
data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0;
for (i = 0;i <= 15;++i) {
if ((i & 0x03) = 0) {
value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4);
}
data->gpio_config[i] = value & 0x03;
value >>= 2;
}
data->last_config = jiffies;
}; /* last_config */
dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
client->id);
data->vid = (data->gpio >> 11) & 0x1f;
data->valid = 1;
up(&data->update_lock);
return data;
}
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val);
adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
up(&data->update_lock);
return count;
}
#define in_reg(offset) \
static ssize_t show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, offset); \
} \
static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, offset); \
} \
static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, offset); \
} \
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max);
in_reg(0);
in_reg(1);
in_reg(2);
in_reg(3);
in_reg(4);
in_reg(5);
in_reg(6);
in_reg(7);
in_reg(8);
in_reg(9);
in_reg(10);
in_reg(11);
in_reg(12);
in_reg(13);
in_reg(14);
in_reg(15);
static ssize_t show_in16(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET);
}
static ssize_t show_in16_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
up(&data->update_lock);
return count;
}
static ssize_t show_in16_max(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET);
}
static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
/* Now add fan read/write functions */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
data->fan_div[nr]));
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
data->fan_div[nr]));
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
data->fan_min[nr]);
up(&data->update_lock);
return count;
}
#define fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min);
fan_offset(1);
fan_offset(2);
fan_offset(3);
fan_offset(4);
fan_offset(5);
fan_offset(6);
fan_offset(7);
fan_offset(8);
/* Adjust fan_min to account for new fan divisor */
void fixup_fan_min(struct device *dev, int fan, int old_div)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int new_min;
int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff) {
return;
}
new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254);
data->fan_min[fan] = new_min;
adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
}
/* Now add fan_div read/write functions */
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->fan_div[nr]);
}
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val,orig_div,new_div,shift;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val);
if (new_div = 0) {
return -EINVAL;
}
down(&data->update_lock);
orig_div = data->fan_div[nr];
data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
(new_div << shift)));
} else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
(new_div << shift)));
}
if (data->fan_div[nr] != orig_div) {
fixup_fan_min(dev,nr,orig_div);
}
up(&data->update_lock);
return count;
}
#define fan_offset_div(offset) \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, offset - 1); \
} \
static ssize_t set_fan_##offset##_div (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_div(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
show_fan_##offset##_div, set_fan_##offset##_div);
fan_offset_div(1);
fan_offset_div(2);
fan_offset_div(3);
fan_offset_div(4);
fan_offset_div(5);
fan_offset_div(6);
fan_offset_div(7);
fan_offset_div(8);
/* Temps */
static ssize_t show_temp(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
}
static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
}
static ssize_t set_temp_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
data->temp_min[nr]);
up(&data->update_lock);
return count;
}
static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
}
static ssize_t set_temp_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
data->temp_max[nr]);
up(&data->update_lock);
return count;
}
#define temp_reg(offset) \
static ssize_t show_temp_##offset (struct device *dev, char *buf) \
{ \
return show_temp(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
{ \
return show_temp_min(dev, buf, offset - 1); \
} \
static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
{ \
return show_temp_max(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_min(dev, buf, count, offset - 1); \
} \
static ssize_t set_temp_##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_max(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
show_temp_##offset##_min, set_temp_##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
show_temp_##offset##_max, set_temp_##offset##_max);
temp_reg(1);
temp_reg(2);
temp_reg(3);
static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
}
static ssize_t set_temp_offset(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_offset[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
data->temp_offset[nr]);
up(&data->update_lock);
return count;
}
#define temp_offset_reg(offset) \
static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
{ \
return show_temp_offset(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_offset (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_offset(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_##offset##_offset, set_temp_##offset##_offset);
temp_offset_reg(1);
temp_offset_reg(2);
temp_offset_reg(3);
static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(
ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
}
static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
ADM1026_FAN_CONTROL_TEMP_RANGE));
}
static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
}
static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_tmin[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
data->temp_tmin[nr]);
up(&data->update_lock);
return count;
}
#define temp_auto_point(offset) \
static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point1_temp(dev, buf, offset - 1); \
} \
static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
*dev, char *buf) \
{ \
return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
} \
static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
char *buf) \
{ \
return show_temp_auto_point2_temp(dev, buf, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
show_temp##offset##_auto_point1_temp, \
set_temp##offset##_auto_point1_temp); \
static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
show_temp##offset##_auto_point1_temp_hyst, NULL); \
static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
show_temp##offset##_auto_point2_temp, NULL);
temp_auto_point(1);
temp_auto_point(2);
temp_auto_point(3);
static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
}
static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
val = simple_strtol(buf, NULL, 10);
if ((val = 1) || (val=0)) {
down(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
up(&data->update_lock);
}
return count;
}
static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
show_temp_crit_enable, set_temp_crit_enable);
static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
}
static ssize_t set_temp_crit(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_crit[nr] = TEMP_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
data->temp_crit[nr]);
up(&data->update_lock);
return count;
}
#define temp_crit_reg(offset) \
static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
{ \
return show_temp_crit(dev, buf, offset - 1); \
} \
static ssize_t set_temp_##offset##_crit (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_temp_crit(dev, buf, count, offset - 1); \
} \
static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
show_temp_##offset##_crit, set_temp_##offset##_crit);
temp_crit_reg(1);
temp_crit_reg(2);
temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
}
static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->analog_out = DAC_TO_REG(val);
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->vrm);
}
static ssize_t store_vrm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
data->vrm = simple_strtol(buf, NULL, 10);
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", (long) (data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
static ssize_t show_alarm_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->alarm_mask);
}
static ssize_t set_alarm_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
unsigned long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->alarm_mask = val & 0x7fffffff;
mask = data->alarm_mask
| (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
adm1026_write_value(client, ADM1026_REG_MASK1,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK2,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK3,
mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_MASK4,
mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask);
static ssize_t show_gpio(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio);
}
static ssize_t set_gpio(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long gpio;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio = val & 0x1ffff;
gpio = data->gpio;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
gpio >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%ld\n", data->gpio_mask);
}
static ssize_t set_gpio_mask(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
long mask;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->gpio_mask = val & 0x1ffff;
mask = data->gpio_mask;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
mask >>= 8;
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
up(&data->update_lock);
return count;
}
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
}
static ssize_t store_pwm_reg(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_pwm_reg(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
if (data->pwm1.enable = 1) {
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.pwm = PWM_TO_REG(val);
return store_pwm_reg(client, data, count);
}
return count;
}
static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
}
static ssize_t store_auto_pwm_min(struct i2c_client *client,
struct adm1026_data *data, size_t count)
{
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
up(&data->update_lock);
return count;
}
static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
if (data->pwm1.enable = 2) { /* apply immediately */
return store_auto_pwm_min(client, data, count);
} else { /* wait til automatic fan control is enabled to apply */
up(&data->update_lock);
return count;
}
}
static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
{
return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
}
static ssize_t show_pwm_enable(struct device *dev, char *buf)
{
struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf,"%d\n", data->pwm1.enable);
}
static ssize_t set_pwm_enable(struct device *dev, const char *buf,
size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client);
int val;
int old_enable;
down(&data->update_lock);
old_enable = data->pwm1.enable;
val = simple_strtol(buf, NULL, 10);
if ((val >= 0) && (val < 3)) {
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC)
| ((val = 2) ? CFG1_PWM_AFC : 0);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
if (val = 2) { /* apply pwm1_auto_pwm_min to pwm1 */
return store_auto_pwm_min(client, data, count);
} else if (!((old_enable = 1) && (val = 1))) {
/* set pwm to safe value */
data->pwm1.pwm = 255;
return store_pwm_reg(client, data, count);
}
}
up(&data->update_lock);
return count;
}
/* enable PWM fan control */
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
set_pwm_enable);
static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
show_auto_pwm_min, set_auto_pwm_min);
static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
int adm1026_detect(struct i2c_adapter *adapter, int address,
int kind)
{
int company, verstep;
struct i2c_client *new_client;
struct adm1026_data *data;
int err = 0;
const char *type_name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
/* We need to be able to do byte I/O */
goto exit;
};
/* 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 adm1026_{read,write}_value. */
if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct adm1026_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1026_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
" COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
i2c_adapter_id(new_client->adapter), new_client->addr,
company, verstep);
/* If auto-detecting, Determine the chip type. */
if (kind <= 0) {
dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
"...\n", i2c_adapter_id(adapter), address);
if (company = ADM1026_COMPANY_ANALOG_DEV
&& verstep = ADM1026_VERSTEP_ADM1026) {
kind = adm1026;
} else if (company = ADM1026_COMPANY_ANALOG_DEV
&& (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Unrecognized stepping "
"0x%02x. Defaulting to ADM1026.\n", verstep);
kind = adm1026;
} else if ((verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
dev_err(&adapter->dev, ": Found version/stepping "
"0x%02x. Assuming generic ADM1026.\n",
verstep);
kind = any_chip;
} else {
dev_dbg(&new_client->dev, ": Autodetection "
"failed\n");
/* Not an ADM1026 ... */
if (kind = 0) { /* User used force=x,y */
dev_err(&adapter->dev, "Generic ADM1026 not "
"found at %d,0x%02x. Try "
"force_adm1026.\n",
i2c_adapter_id(adapter), address);
}
err = 0;
goto exitfree;
}
}
/* Fill in the chip specific driver values */
switch (kind) {
case any_chip :
type_name = "adm1026";
break;
case adm1026 :
type_name = "adm1026";
break;
default :
dev_err(&adapter->dev, ": Internal error, invalid "
"kind (%d)!", kind);
err = -EFAULT;
goto exitfree;
}
strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
/* Fill in the remaining client fields */
new_client->id = adm1026_id++;
data->type = kind;
data->valid = 0;
init_MUTEX(&data->update_lock);
dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
new_client->id, new_client->id, new_client->name,
i2c_adapter_id(new_client->adapter),
new_client->addr);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
goto exitfree;
/* Set the VRM version */
data->vrm = i2c_which_vrm();
/* Initialize the ADM1026 chip */
adm1026_init_client(new_client);
/* Register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in0_input);
device_create_file(&new_client->dev, &dev_attr_in0_max);
device_create_file(&new_client->dev, &dev_attr_in0_min);
device_create_file(&new_client->dev, &dev_attr_in1_input);
device_create_file(&new_client->dev, &dev_attr_in1_max);
device_create_file(&new_client->dev, &dev_attr_in1_min);
device_create_file(&new_client->dev, &dev_attr_in2_input);
device_create_file(&new_client->dev, &dev_attr_in2_max);
device_create_file(&new_client->dev, &dev_attr_in2_min);
device_create_file(&new_client->dev, &dev_attr_in3_input);
device_create_file(&new_client->dev, &dev_attr_in3_max);
device_create_file(&new_client->dev, &dev_attr_in3_min);
device_create_file(&new_client->dev, &dev_attr_in4_input);
device_create_file(&new_client->dev, &dev_attr_in4_max);
device_create_file(&new_client->dev, &dev_attr_in4_min);
device_create_file(&new_client->dev, &dev_attr_in5_input);
device_create_file(&new_client->dev, &dev_attr_in5_max);
device_create_file(&new_client->dev, &dev_attr_in5_min);
device_create_file(&new_client->dev, &dev_attr_in6_input);
device_create_file(&new_client->dev, &dev_attr_in6_max);
device_create_file(&new_client->dev, &dev_attr_in6_min);
device_create_file(&new_client->dev, &dev_attr_in7_input);
device_create_file(&new_client->dev, &dev_attr_in7_max);
device_create_file(&new_client->dev, &dev_attr_in7_min);
device_create_file(&new_client->dev, &dev_attr_in8_input);
device_create_file(&new_client->dev, &dev_attr_in8_max);
device_create_file(&new_client->dev, &dev_attr_in8_min);
device_create_file(&new_client->dev, &dev_attr_in9_input);
device_create_file(&new_client->dev, &dev_attr_in9_max);
device_create_file(&new_client->dev, &dev_attr_in9_min);
device_create_file(&new_client->dev, &dev_attr_in10_input);
device_create_file(&new_client->dev, &dev_attr_in10_max);
device_create_file(&new_client->dev, &dev_attr_in10_min);
device_create_file(&new_client->dev, &dev_attr_in11_input);
device_create_file(&new_client->dev, &dev_attr_in11_max);
device_create_file(&new_client->dev, &dev_attr_in11_min);
device_create_file(&new_client->dev, &dev_attr_in12_input);
device_create_file(&new_client->dev, &dev_attr_in12_max);
device_create_file(&new_client->dev, &dev_attr_in12_min);
device_create_file(&new_client->dev, &dev_attr_in13_input);
device_create_file(&new_client->dev, &dev_attr_in13_max);
device_create_file(&new_client->dev, &dev_attr_in13_min);
device_create_file(&new_client->dev, &dev_attr_in14_input);
device_create_file(&new_client->dev, &dev_attr_in14_max);
device_create_file(&new_client->dev, &dev_attr_in14_min);
device_create_file(&new_client->dev, &dev_attr_in15_input);
device_create_file(&new_client->dev, &dev_attr_in15_max);
device_create_file(&new_client->dev, &dev_attr_in15_min);
device_create_file(&new_client->dev, &dev_attr_in16_input);
device_create_file(&new_client->dev, &dev_attr_in16_max);
device_create_file(&new_client->dev, &dev_attr_in16_min);
device_create_file(&new_client->dev, &dev_attr_fan1_input);
device_create_file(&new_client->dev, &dev_attr_fan1_div);
device_create_file(&new_client->dev, &dev_attr_fan1_min);
device_create_file(&new_client->dev, &dev_attr_fan2_input);
device_create_file(&new_client->dev, &dev_attr_fan2_div);
device_create_file(&new_client->dev, &dev_attr_fan2_min);
device_create_file(&new_client->dev, &dev_attr_fan3_input);
device_create_file(&new_client->dev, &dev_attr_fan3_div);
device_create_file(&new_client->dev, &dev_attr_fan3_min);
device_create_file(&new_client->dev, &dev_attr_fan4_input);
device_create_file(&new_client->dev, &dev_attr_fan4_div);
device_create_file(&new_client->dev, &dev_attr_fan4_min);
device_create_file(&new_client->dev, &dev_attr_fan5_input);
device_create_file(&new_client->dev, &dev_attr_fan5_div);
device_create_file(&new_client->dev, &dev_attr_fan5_min);
device_create_file(&new_client->dev, &dev_attr_fan6_input);
device_create_file(&new_client->dev, &dev_attr_fan6_div);
device_create_file(&new_client->dev, &dev_attr_fan6_min);
device_create_file(&new_client->dev, &dev_attr_fan7_input);
device_create_file(&new_client->dev, &dev_attr_fan7_div);
device_create_file(&new_client->dev, &dev_attr_fan7_min);
device_create_file(&new_client->dev, &dev_attr_fan8_input);
device_create_file(&new_client->dev, &dev_attr_fan8_div);
device_create_file(&new_client->dev, &dev_attr_fan8_min);
device_create_file(&new_client->dev, &dev_attr_temp1_input);
device_create_file(&new_client->dev, &dev_attr_temp1_max);
device_create_file(&new_client->dev, &dev_attr_temp1_min);
device_create_file(&new_client->dev, &dev_attr_temp2_input);
device_create_file(&new_client->dev, &dev_attr_temp2_max);
device_create_file(&new_client->dev, &dev_attr_temp2_min);
device_create_file(&new_client->dev, &dev_attr_temp3_input);
device_create_file(&new_client->dev, &dev_attr_temp3_max);
device_create_file(&new_client->dev, &dev_attr_temp3_min);
device_create_file(&new_client->dev, &dev_attr_temp1_offset);
device_create_file(&new_client->dev, &dev_attr_temp2_offset);
device_create_file(&new_client->dev, &dev_attr_temp3_offset);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point1_temp_hyst);
device_create_file(&new_client->dev,
&dev_attr_temp1_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp2_auto_point2_temp);
device_create_file(&new_client->dev,
&dev_attr_temp3_auto_point2_temp);
device_create_file(&new_client->dev, &dev_attr_temp1_crit);
device_create_file(&new_client->dev, &dev_attr_temp2_crit);
device_create_file(&new_client->dev, &dev_attr_temp3_crit);
device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
device_create_file(&new_client->dev, &dev_attr_vid);
device_create_file(&new_client->dev, &dev_attr_vrm);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_alarm_mask);
device_create_file(&new_client->dev, &dev_attr_gpio);
device_create_file(&new_client->dev, &dev_attr_gpio_mask);
device_create_file(&new_client->dev, &dev_attr_pwm1);
device_create_file(&new_client->dev, &dev_attr_pwm2);
device_create_file(&new_client->dev, &dev_attr_pwm3);
device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
device_create_file(&new_client->dev, &dev_attr_analog_out);
return 0;
/* Error out and cleanup code */
exitfree:
kfree(new_client);
exit:
return err;
}
static int __init sm_adm1026_init(void)
{
return i2c_add_driver(&adm1026_driver);
}
static void __exit sm_adm1026_exit(void)
{
i2c_del_driver(&adm1026_driver);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
"Justin Thiessen <jthiessen@penguincomputing.com>");
MODULE_DESCRIPTION("ADM1026 driver");
module_init(sm_adm1026_init);
module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, sensors, linux-kernel
Hi Justin,
> Ok, let's try this (yet) again:
I'm sorry to insist be we really want this as a patch against
2.6.10-rc2. That's what Greg needs. As said earlier, the patch would
include the new adm1026.c file (obviously) as well as the necessary
changes to Kconfig and Makefile.
Other than that I'm fine with the code itself.
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Arjan van de Ven
0 siblings, 0 replies; 51+ messages in thread
From: Arjan van de Ven @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, phil, khali, sensors, linux-kernel
On Thu, 2004-11-18 at 10:56 -0800, Justin Thiessen wrote:
> MODULE_PARM(gpio_input,"1-17i");
new 2.6 drivers should NOT use MODULE_PARM, it's deprecated.
use module_param() instead
> int adm1026_attach_adapter(struct i2c_adapter *adapter)
> {
> if (!(adapter->class & I2C_CLASS_HWMON)) {
> return 0;
> }
no need for extra { }'s in such a case
> static ssize_t show_in(struct device *dev, char *buf, int nr)
> {
> struct adm1026_data *data = adm1026_update_device(dev);
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> }
any chance you could make this use snprintf instead ?
> static ssize_t show_in_max(struct device *dev, char *buf, int nr)
> {
> struct adm1026_data *data = adm1026_update_device(dev);
> return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
> }
same question
> static ssize_t store_pwm_reg(struct i2c_client *client,
> struct adm1026_data *data, size_t count)
> {
> adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
> up(&data->update_lock);
> return count;
> }
> static ssize_t set_pwm_reg(struct device *dev, const char *buf,
> size_t count)
> {
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> if (data->pwm1.enable = 1) {
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->pwm1.pwm = PWM_TO_REG(val);
> return store_pwm_reg(client, data, count);
> }
this locking construct is rahter awkward; is it possible to refactor the
code such that you can down and up in the same function ?
> static ssize_t store_auto_pwm_min(struct i2c_client *client,
> struct adm1026_data *data, size_t count)
> {
> data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
> PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
> adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
> up(&data->update_lock);
> return count;
> }
> static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
> size_t count)
> {
> struct i2c_client *client = to_i2c_client(dev);
> struct adm1026_data *data = i2c_get_clientdata(client);
> int val;
>
> down(&data->update_lock);
> val = simple_strtol(buf, NULL, 10);
> data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
> if (data->pwm1.enable = 2) { /* apply immediately */
> return store_auto_pwm_min(client, data, count);
> } else { /* wait til automatic fan control is enabled to apply */
> up(&data->update_lock);
> return count;
> }
> }
.. here the same construct but even more awkward
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Justin Thiessen, Greg KH, LM Sensors, LKML
Hi Arjan,
> > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > {
> > struct adm1026_data *data = adm1026_update_device(dev);
> > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > }
>
> any chance you could make this use snprintf instead ?
None of the other hardware monitoring clients driver do, nor do I think
they should. What are we trying to improve?
Thanks.
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: LM Sensors; +Cc: greg, linux-kernel
On Sat, Nov 20, 2004 at 10:57:40AM +0100, Jean Delvare wrote:
> Hi Justin,
>
> > Ok, let's try this (yet) again:
>
> I'm sorry to insist be we really want this as a patch against
> 2.6.10-rc2. That's what Greg needs. As said earlier, the patch would
> include the new adm1026.c file (obviously) as well as the necessary
> changes to Kconfig and Makefile.
Ack. Sorry for forgetting the Kconfig and Makefile changes.
The driver itself is actually a patch against 2.6.10-rc2.
I'll post the driver once the issues Arjan raised have been resolved.
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: greg, phil, khali, sensors, linux-kernel
On Sat, Nov 20, 2004 at 11:13:56AM +0100, Arjan van de Ven wrote:
> On Thu, 2004-11-18 at 10:56 -0800, Justin Thiessen wrote:
> > MODULE_PARM(gpio_input,"1-17i");
>
> new 2.6 drivers should NOT use MODULE_PARM, it's deprecated.
> use module_param() instead
Ok. You mean module_param_array() in these particular cases, right?
> > int adm1026_attach_adapter(struct i2c_adapter *adapter)
> > {
> > if (!(adapter->class & I2C_CLASS_HWMON)) {
> > return 0;
> > }
>
> no need for extra { }'s in such a case
Of course there's no _need_. But I find the result stylistically easier to
read. Is there any real objection?
> > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > {
> > struct adm1026_data *data = adm1026_update_device(dev);
> > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > }
>
> any chance you could make this use snprintf instead ?
I'll defer to Jean's response...
<snip awkward locking construct>
> this locking construct is rahter awkward; is it possible to refactor the
> code such that you can down and up in the same function ?
Yes, at the cost of some minor code duplication or the introduction of
another variable. Is that preferable? Is holding the lock across function
calls a Bad Idea?
Justin Thiessen
---------------
jthiessen@penguincomputing.com
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Arjan van de Ven
0 siblings, 0 replies; 51+ messages in thread
From: Arjan van de Ven @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: greg, phil, khali, sensors, linux-kernel
> > this locking construct is rahter awkward; is it possible to refactor the
> > code such that you can down and up in the same function ?
>
> Yes, at the cost of some minor code duplication or the introduction of
> another variable. Is that preferable? Is holding the lock across function
> calls a Bad Idea?
holding lock across function calls isn't, unlocking in another function than you take the lock is.
For one it makes auditing the code a lot harder.
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` linux-os
0 siblings, 0 replies; 51+ messages in thread
From: linux-os @ 2005-05-19 6:25 UTC (permalink / raw)
To: Arjan van de Ven
Cc: Justin Thiessen, greg, phil, khali, sensors, linux-kernel
On Mon, 22 Nov 2004, Arjan van de Ven wrote:
>
>>> this locking construct is rahter awkward; is it possible to refactor the
>>> code such that you can down and up in the same function ?
>>
>> Yes, at the cost of some minor code duplication or the introduction of
>> another variable. Is that preferable? Is holding the lock across function
>> calls a Bad Idea?
>
> holding lock across function calls isn't, unlocking in another function
> than you take the lock is.
> For one it makes auditing the code a lot harder.
>
Also, code like:
down(&mylock);
do_something();
if(fail) {
up(&mylock);
return retval;
}
.. is prone to errors where a lock never gets released on some
corner cases. It's often better to "goto" a common exit point where
the lock is released.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by John Ashcroft.
98.36% of all statistics are fiction.
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver,
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: greg, phil; +Cc: khali, sensors, linux-kernel
Hi,
Taking into account Arjan's comments, I have fixed the awkward locking
constructs. I have also switched from using MODULE_PARM() to
module_param_array(). As Jean requested (and as I muttonheadedly ignored)
on the last submission, the diff now includes the patches to
../drivers/i2c/chips/Makefile
../drivers/i2c/chips/Kconfig
Finally (and you've all read this before):
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed off by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig linux-2.6.10-rc2/drivers/i2c/chips/Kconfig
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Kconfig 2004-11-16 17:09:36.000000000 -0800
@@ -32,6 +32,15 @@ config SENSORS_ADM1025
This driver can also be built as a module. If so, the module
will be called adm1025.
+config SENSORS_ADM1026
+ tristate "Analog Devices ADM1026 and compatibles"
+ depends on I2C && EXPERIMENTAL
+ select I2C_SENSOR
+ help
+ If you say yes here you get support for Analog Devices ADM1026
+ This driver can also be built as a module. If so, the module
+ will be called adm1026.
+
config SENSORS_ADM1031
tristate "Analog Devices ADM1031 and compatibles"
depends on I2C && EXPERIMENTAL
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile linux-2.6.10-rc2/drivers/i2c/chips/Makefile
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Makefile 2004-11-16 17:09:10.000000000 -0800
@@ -9,6 +9,7 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
+obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c 1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c 2004-11-22 13:14:39.000000000 -0800
@@ -0,0 +1,1779 @@
+/*
+ adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
+ monitoring
+ Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
+ Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
+
+ Chip details at:
+
+ <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
+
+ 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 <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c-sensor.h>
+#include <linux/i2c-vid.h>
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
+static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
+
+/* Insmod parameters */
+SENSORS_INSMOD_1(adm1026);
+
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+module_param_array(gpio_input,int,NULL,0);
+MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output,int,NULL,0);
+MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+ "outputs");
+module_param_array(gpio_inverted,int,NULL,0);
+MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+ "inverted");
+module_param_array(gpio_normal,int,NULL,0);
+MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+ "normal/non-inverted");
+module_param_array(gpio_fan,int,NULL,0);
+MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+
+/* Many ADM1026 constants specified below */
+
+/* The ADM1026 registers */
+#define ADM1026_REG_CONFIG1 0x00
+#define CFG1_MONITOR 0x01
+#define CFG1_INT_ENABLE 0x02
+#define CFG1_INT_CLEAR 0x04
+#define CFG1_AIN8_9 0x08
+#define CFG1_THERM_HOT 0x10
+#define CFG1_DAC_AFC 0x20
+#define CFG1_PWM_AFC 0x40
+#define CFG1_RESET 0x80
+#define ADM1026_REG_CONFIG2 0x01
+/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
+#define ADM1026_REG_CONFIG3 0x07
+#define CFG3_GPIO16_ENABLE 0x01
+#define CFG3_CI_CLEAR 0x02
+#define CFG3_VREF_250 0x04
+#define CFG3_GPIO16_DIR 0x40
+#define CFG3_GPIO16_POL 0x80
+#define ADM1026_REG_E2CONFIG 0x13
+#define E2CFG_READ 0x01
+#define E2CFG_WRITE 0x02
+#define E2CFG_ERASE 0x04
+#define E2CFG_ROM 0x08
+#define E2CFG_CLK_EXT 0x80
+
+/* There are 10 general analog inputs and 7 dedicated inputs
+ * They are:
+ * 0 - 9 = AIN0 - AIN9
+ * 10 = Vbat
+ * 11 = 3.3V Standby
+ * 12 = 3.3V Main
+ * 13 = +5V
+ * 14 = Vccp (CPU core voltage)
+ * 15 = +12V
+ * 16 = -12V
+ */
+static u16 ADM1026_REG_IN[] = {
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
+ 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
+ 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
+ };
+static u16 ADM1026_REG_IN_MIN[] = {
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
+ 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
+ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+static u16 ADM1026_REG_IN_MAX[] = {
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
+ 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
+ 0x43, 0x44, 0x45, 0x46, 0x47
+ };
+
+/* Temperatures are:
+ * 0 - Internal
+ * 1 - External 1
+ * 2 - External 2
+ */
+static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
+static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
+static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
+static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
+static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
+static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
+
+#define ADM1026_REG_FAN(nr) (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3 0x02
+#define ADM1026_REG_FAN_DIV_4_7 0x03
+
+#define ADM1026_REG_DAC 0x04
+#define ADM1026_REG_PWM 0x05
+
+#define ADM1026_REG_GPIO_CFG_0_3 0x08
+#define ADM1026_REG_GPIO_CFG_4_7 0x09
+#define ADM1026_REG_GPIO_CFG_8_11 0x0a
+#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+/* CFG_16 in REG_CFG3 */
+#define ADM1026_REG_GPIO_STATUS_0_7 0x24
+#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+/* STATUS_16 in REG_STATUS4 */
+#define ADM1026_REG_GPIO_MASK_0_7 0x1c
+#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+/* MASK_16 in REG_MASK4 */
+
+#define ADM1026_REG_COMPANY 0x16
+#define ADM1026_REG_VERSTEP 0x17
+/* These are the recognized values for the above regs */
+#define ADM1026_COMPANY_ANALOG_DEV 0x41
+#define ADM1026_VERSTEP_GENERIC 0x40
+#define ADM1026_VERSTEP_ADM1026 0x44
+
+#define ADM1026_REG_MASK1 0x18
+#define ADM1026_REG_MASK2 0x19
+#define ADM1026_REG_MASK3 0x1a
+#define ADM1026_REG_MASK4 0x1b
+
+#define ADM1026_REG_STATUS1 0x20
+#define ADM1026_REG_STATUS2 0x21
+#define ADM1026_REG_STATUS3 0x22
+#define ADM1026_REG_STATUS4 0x23
+
+#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX 255
+
+/* 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.
+ */
+
+/* IN are scaled acording to built-in resistors. These are the
+ * voltages corresponding to 3/4 of full scale (192 or 0xc0)
+ * NOTE: The -12V input needs an additional factor to account
+ * for the Vref pullup resistor.
+ * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
+ * = 13875 * 2.50 / 1.875 - 2500
+ * = 16000
+ *
+ * The values in this table are based on Table II, page 15 of the
+ * datasheet.
+ */
+static int adm1026_scaling[] = { /* .001 Volts */
+ 2250, 2250, 2250, 2250, 2250, 2250,
+ 1875, 1875, 1875, 1875, 3000, 3330,
+ 3330, 4995, 2250, 12000, 13875
+ };
+#define NEG12_OFFSET 16000
+#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
+ 0,255))
+#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+
+/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
+ * and we assume a 2 pulse-per-rev fan tach signal
+ * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
+ */
+#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
+ (div)),1,254))
+#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
+ (div)))
+#define DIV_FROM_REG(val) (1<<(val))
+#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+
+/* Temperature is reported in 1 degC increments */
+#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define TEMP_FROM_REG(val) ((val) * 1000)
+#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define OFFSET_FROM_REG(val) ((val) * 1000)
+
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_FROM_REG(val) (val)
+
+#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
+#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
+
+/* Analog output is a voltage, and scaled to millivolts. The datasheet
+ * indicates that the DAC could be used to drive the fans, but in our
+ * example board (Arima HDAMA) it isn't connected to the fans at all.
+ */
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
+#define DAC_FROM_REG(val) (((val)*2500)/255)
+
+/* Typically used with systems using a v9.1 VRM spec ? */
+#define ADM1026_INIT_VRM 91
+
+/* Chip sampling rates
+ *
+ * Some sensors are not updated more frequently than once per second
+ * so it doesn't make sense to read them more often than that.
+ * We cache the results and return the saved data if the driver
+ * is called again before a second has elapsed.
+ *
+ * Also, there is significant configuration data for this chip
+ * So, we keep the config data up to date in the cache
+ * when it is written and only sample it once every 5 *minutes*
+ */
+#define ADM1026_DATA_INTERVAL (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
+
+/* We allow for multiple chips in a single system.
+ *
+ * For each registered ADM1026, we need to keep state information
+ * at client->data. The adm1026_data structure is dynamically
+ * allocated, when a new client structure is allocated. */
+
+struct pwm_data {
+ u8 pwm;
+ u8 enable;
+ u8 auto_pwm_min;
+};
+
+struct adm1026_data {
+ struct i2c_client client;
+ struct semaphore lock;
+ enum chips type;
+
+ struct semaphore update_lock;
+ int valid; /* !=0 if following fields are valid */
+ unsigned long last_reading; /* In jiffies */
+ unsigned long last_config; /* In jiffies */
+
+ u8 in[17]; /* Register value */
+ u8 in_max[17]; /* Register value */
+ u8 in_min[17]; /* Register value */
+ s8 temp[3]; /* Register value */
+ s8 temp_min[3]; /* Register value */
+ s8 temp_max[3]; /* Register value */
+ s8 temp_tmin[3]; /* Register value */
+ s8 temp_crit[3]; /* Register value */
+ s8 temp_offset[3]; /* Register value */
+ u8 fan[8]; /* Register value */
+ u8 fan_min[8]; /* Register value */
+ u8 fan_div[8]; /* Decoded value */
+ struct pwm_data pwm1; /* Pwm control values */
+ int vid; /* Decoded value */
+ u8 vrm; /* VRM version */
+ u8 analog_out; /* Register value (DAC) */
+ long alarms; /* Register encoding, combined */
+ long alarm_mask; /* Register encoding, combined */
+ long gpio; /* Register encoding, combined */
+ long gpio_mask; /* Register encoding, combined */
+ u8 gpio_config[17]; /* Decoded value */
+ u8 config1; /* Register value */
+ u8 config2; /* Register value */
+ u8 config3; /* Register value */
+};
+
+static int adm1026_attach_adapter(struct i2c_adapter *adapter);
+static int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind);
+static int adm1026_detach_client(struct i2c_client *client);
+static int adm1026_read_value(struct i2c_client *client, u8 register);
+static int adm1026_write_value(struct i2c_client *client, u8 register,
+ int value);
+static void adm1026_print_gpio(struct i2c_client *client);
+static void adm1026_fixup_gpio(struct i2c_client *client);
+static struct adm1026_data *adm1026_update_device(struct device *dev);
+static void adm1026_init_client(struct i2c_client *client);
+
+
+static struct i2c_driver adm1026_driver = {
+ .owner = THIS_MODULE,
+ .name = "adm1026",
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = adm1026_attach_adapter,
+ .detach_client = adm1026_detach_client,
+};
+
+static int adm1026_id;
+
+int adm1026_attach_adapter(struct i2c_adapter *adapter)
+{
+ if (!(adapter->class & I2C_CLASS_HWMON)) {
+ return 0;
+ }
+ return i2c_detect(adapter, &addr_data, adm1026_detect);
+}
+
+int adm1026_detach_client(struct i2c_client *client)
+{
+ i2c_detach_client(client);
+ kfree(client);
+ return 0;
+}
+
+int adm1026_read_value(struct i2c_client *client, u8 reg)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_read_byte_data(client, reg) & 0xff;
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_write_byte_data(client, reg, value);
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+void adm1026_init_client(struct i2c_client *client)
+{
+ int value, i;
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
+ /* Read chip config */
+ data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
+
+ /* Inform user of chip config */
+ dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
+ client->id, data->config1);
+ if ((data->config1 & CFG1_MONITOR) = 0) {
+ dev_dbg(&client->dev, "(%d): Monitoring not currently "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_INT_ENABLE) {
+ dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_AIN8_9) {
+ dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
+ "temp3 disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
+ "in9 disabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_THERM_HOT) {
+ dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
+ "and temp limits enabled.\n", client->id);
+ }
+
+ value = data->config3;
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
+ "pin disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): THERM pin enabled. "
+ "GPIO16 disabled.\n", client->id);
+ }
+ if (data->config3 & CFG3_VREF_250) {
+ dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
+ client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
+ client->id);
+ }
+ /* Read and pick apart the existing GPIO configuration */
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) = 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ /* ... and then print it */
+ adm1026_print_gpio(client);
+
+ /* If the user asks us to reprogram the GPIO config, then
+ * do it now. But only if this is the first ADM1026.
+ */
+ if (client->id = 0
+ && (gpio_input[0] != -1 || gpio_output[0] != -1
+ || gpio_inverted[0] != -1 || gpio_normal[0] != -1
+ || gpio_fan[0] != -1)) {
+ adm1026_fixup_gpio(client);
+ }
+
+ /* WE INTENTIONALLY make no changes to the limits,
+ * offsets, pwms, fans and zones. If they were
+ * configured, we don't want to mess with them.
+ * If they weren't, the default is 100% PWM, no
+ * control and will suffice until 'sensors -s'
+ * can be run by the user. We DO set the default
+ * value for pwm1.auto_pwm_min to its maximum
+ * so that enabling automatic pwm fan control
+ * without first setting a value for pwm1.auto_pwm_min
+ * will not result in potentially dangerous fan speed decrease.
+ */
+ data->pwm1.auto_pwm_min%5;
+ /* Start monitoring */
+ value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ /* Set MONITOR, clear interrupt acknowledge and s/w reset */
+ value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
+ dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
+ client->id, value);
+ data->config1 = value;
+ adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
+}
+
+void adm1026_print_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+
+ dev_dbg(&client->dev, "(%d): GPIO config is:",
+ client->id);
+ for (i = 0;i <= 7;++i) {
+ if (data->config2 & (1 << i)) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ } else {
+ dev_dbg(&client->dev, "\t(%d): FAN%d\n",
+ client->id, i);
+ }
+ }
+ for (i = 8;i <= 15;++i) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ }
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
+ data->gpio_config[16] & 0x02 ? "" : "!",
+ data->gpio_config[16] & 0x01 ? "OUT" : "IN");
+ } else {
+ /* GPIO16 is THERM */
+ dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
+ }
+}
+
+void adm1026_fixup_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ int value;
+
+ /* Make the changes requested. */
+ /* We may need to unlock/stop monitoring or soft-reset the
+ * chip before we can make changes. This hasn't been
+ * tested much. FIXME
+ */
+
+ /* Make outputs */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
+ data->gpio_config[gpio_output[i]] |= 0x01;
+ }
+ /* if GPIO0-7 is output, it isn't a FAN tach */
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
+ data->config2 |= 1 << gpio_output[i];
+ }
+ }
+
+ /* Input overrides output */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
+ data->gpio_config[gpio_input[i]] &= ~ 0x01;
+ }
+ /* if GPIO0-7 is input, it isn't a FAN tach */
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
+ data->config2 |= 1 << gpio_input[i];
+ }
+ }
+
+ /* Inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
+ data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
+ }
+ }
+
+ /* Normal overrides inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
+ data->gpio_config[gpio_normal[i]] |= 0x02;
+ }
+ }
+
+ /* Fan overrides input and output */
+ for (i = 0;i <= 7;++i) {
+ if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
+ data->config2 &= ~(1 << gpio_fan[i]);
+ }
+ }
+
+ /* Write new configs to registers */
+ adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
+ data->config3 = (data->config3 & 0x3f)
+ | ((data->gpio_config[16] & 0x03) << 6);
+ adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
+ for (i = 15, value = 0;i >= 0;--i) {
+ value <<= 2;
+ value |= data->gpio_config[i] & 0x03;
+ if ((i & 0x03) = 0) {
+ adm1026_write_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4,
+ value);
+ value = 0;
+ }
+ }
+
+ /* Print the new config */
+ adm1026_print_gpio(client);
+}
+
+
+static struct adm1026_data *adm1026_update_device(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ long value, alarms, gpio;
+
+ down(&data->update_lock);
+ if (!data->valid
+ || (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
+ /* Things that change quickly */
+ dev_dbg(&client->dev,"(%d): Reading sensor values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in[i] + adm1026_read_value(client, ADM1026_REG_IN[i]);
+ }
+
+ for (i = 0;i <= 7;++i) {
+ data->fan[i] + adm1026_read_value(client, ADM1026_REG_FAN(i));
+ }
+
+ for (i = 0;i <= 2;++i) {
+ /* NOTE: temp[] is s8 and we assume 2's complement
+ * "conversion" in the assignment */
+ data->temp[i] + adm1026_read_value(client, ADM1026_REG_TEMP[i]);
+ }
+
+ data->pwm1.pwm = adm1026_read_value(client,
+ ADM1026_REG_PWM);
+ data->analog_out = adm1026_read_value(client,
+ ADM1026_REG_DAC);
+ /* GPIO16 is MSbit of alarms, move it to gpio */
+ alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms &= 0x7f;
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
+ data->alarms = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_0_7);
+ data->gpio = gpio;
+
+ data->last_reading = jiffies;
+ }; /* last_reading */
+
+ if (!data->valid || (jiffies - data->last_config >
+ ADM1026_CONFIG_INTERVAL)) {
+ /* Things that don't change often */
+ dev_dbg(&client->dev, "(%d): Reading config values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in_min[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MIN[i]);
+ data->in_max[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MAX[i]);
+ }
+
+ value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
+ | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
+ << 8);
+ for (i = 0;i <= 7;++i) {
+ data->fan_min[i] = adm1026_read_value(client,
+ ADM1026_REG_FAN_MIN(i));
+ data->fan_div[i] = DIV_FROM_REG(value & 0x03);
+ value >>= 2;
+ }
+
+ for (i = 0; i <= 2; ++i) {
+ /* NOTE: temp_xxx[] are s8 and we assume 2's
+ * complement "conversion" in the assignment
+ */
+ data->temp_min[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MIN[i]);
+ data->temp_max[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MAX[i]);
+ data->temp_tmin[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_TMIN[i]);
+ data->temp_crit[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_THERM[i]);
+ data->temp_offset[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_OFFSET[i]);
+ }
+
+ /* Read the STATUS/alarm masks */
+ alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms = (alarms & 0x7f) << 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
+ data->alarm_mask = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_MASK_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
+ data->gpio_mask = gpio;
+
+ /* Read various values from CONFIG1 */
+ data->config1 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG1);
+ if (data->config1 & CFG1_PWM_AFC) {
+ data->pwm1.enable = 2;
+ data->pwm1.auto_pwm_min =
+ PWM_MIN_FROM_REG(data->pwm1.pwm);
+ }
+ /* Read the GPIO config */
+ data->config2 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG3);
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) = 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+
+ data->last_config = jiffies;
+ }; /* last_config */
+
+ dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
+ client->id);
+ data->vid = (data->gpio >> 11) & 0x1f;
+ data->valid = 1;
+ up(&data->update_lock);
+ return data;
+}
+
+static ssize_t show_in(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+}
+static ssize_t show_in_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+}
+static ssize_t set_in_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+}
+static ssize_t set_in_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define in_reg(offset) \
+static ssize_t show_in##offset (struct device *dev, char *buf) \
+{ \
+ return show_in(dev, buf, offset); \
+} \
+static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_in_min(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_min(dev, buf, count, offset); \
+} \
+static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_in_max(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_max(dev, buf, count, offset); \
+} \
+static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
+static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
+ show_in##offset##_min, set_in##offset##_min); \
+static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
+ show_in##offset##_max, set_in##offset##_max);
+
+
+in_reg(0);
+in_reg(1);
+in_reg(2);
+in_reg(3);
+in_reg(4);
+in_reg(5);
+in_reg(6);
+in_reg(7);
+in_reg(8);
+in_reg(9);
+in_reg(10);
+in_reg(11);
+in_reg(12);
+in_reg(13);
+in_reg(14);
+in_reg(15);
+
+static ssize_t show_in16(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+ NEG12_OFFSET);
+}
+static ssize_t show_in16_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in16_max(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
+static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
+static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
+
+
+
+
+/* Now add fan read/write functions */
+
+static ssize_t show_fan(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+ data->fan_div[nr]));
+}
+static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+ data->fan_div[nr]));
+}
+static ssize_t set_fan_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
+ data->fan_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset(offset) \
+static ssize_t show_fan_##offset (struct device *dev, char *buf) \
+{ \
+ return show_fan(dev, buf, offset - 1); \
+} \
+static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_fan_min(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_min(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
+static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_min, set_fan_##offset##_min);
+
+fan_offset(1);
+fan_offset(2);
+fan_offset(3);
+fan_offset(4);
+fan_offset(5);
+fan_offset(6);
+fan_offset(7);
+fan_offset(8);
+
+/* Adjust fan_min to account for new fan divisor */
+void fixup_fan_min(struct device *dev, int fan, int old_div)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int new_min;
+ int new_div = data->fan_div[fan];
+
+ /* 0 and 0xff are special. Don't adjust them */
+ if (data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff) {
+ return;
+ }
+
+ new_min = data->fan_min[fan] * old_div / new_div;
+ new_min = SENSORS_LIMIT(new_min, 1, 254);
+ data->fan_min[fan] = new_min;
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
+}
+
+/* Now add fan_div read/write functions */
+static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->fan_div[nr]);
+}
+static ssize_t set_fan_div(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val,orig_div,new_div,shift;
+
+ val = simple_strtol(buf, NULL, 10);
+ new_div = DIV_TO_REG(val);
+ if (new_div = 0) {
+ return -EINVAL;
+ }
+ down(&data->update_lock);
+ orig_div = data->fan_div[nr];
+ data->fan_div[nr] = DIV_FROM_REG(new_div);
+
+ if (nr < 4) { /* 0 <= nr < 4 */
+ shift = 2 * nr;
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
+ (new_div << shift)));
+ } else { /* 3 < nr < 8 */
+ shift = 2 * (nr - 4);
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
+ (new_div << shift)));
+ }
+
+ if (data->fan_div[nr] != orig_div) {
+ fixup_fan_min(dev,nr,orig_div);
+ }
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset_div(offset) \
+static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
+{ \
+ return show_fan_div(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_div (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_div(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_div, set_fan_##offset##_div);
+
+fan_offset_div(1);
+fan_offset_div(2);
+fan_offset_div(3);
+fan_offset_div(4);
+fan_offset_div(5);
+fan_offset_div(6);
+fan_offset_div(7);
+fan_offset_div(8);
+
+/* Temps */
+static ssize_t show_temp(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+}
+static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+}
+static ssize_t set_temp_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_min[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
+ data->temp_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+}
+static ssize_t set_temp_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_max[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
+ data->temp_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+#define temp_reg(offset) \
+static ssize_t show_temp_##offset (struct device *dev, char *buf) \
+{ \
+ return show_temp(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_temp_min(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_temp_max(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_min(dev, buf, count, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_max(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
+static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_min, set_temp_##offset##_min); \
+static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_max, set_temp_##offset##_max);
+
+
+temp_reg(1);
+temp_reg(2);
+temp_reg(3);
+
+static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+}
+static ssize_t set_temp_offset(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_offset[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
+ data->temp_offset[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_offset_reg(offset) \
+static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
+{ \
+ return show_temp_offset(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_offset (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_offset(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_offset, set_temp_##offset##_offset);
+
+temp_offset_reg(1);
+temp_offset_reg(2);
+temp_offset_reg(3);
+
+static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(
+ ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
+}
+static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+ ADM1026_FAN_CONTROL_TEMP_RANGE));
+}
+static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+}
+static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_tmin[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
+ data->temp_tmin[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_auto_point(offset) \
+static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point1_temp(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
+ *dev, char *buf) \
+{ \
+ return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point2_temp(dev, buf, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
+ show_temp##offset##_auto_point1_temp, \
+ set_temp##offset##_auto_point1_temp); \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
+ show_temp##offset##_auto_point1_temp_hyst, NULL); \
+static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
+ show_temp##offset##_auto_point2_temp, NULL);
+
+temp_auto_point(1);
+temp_auto_point(2);
+temp_auto_point(3);
+
+static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+}
+static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val = 1) || (val=0)) {
+ down(&data->update_lock);
+ data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+
+static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+}
+static ssize_t set_temp_crit(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_crit[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
+ data->temp_crit[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_crit_reg(offset) \
+static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
+{ \
+ return show_temp_crit(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_crit (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_crit(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_crit, set_temp_##offset##_crit);
+
+temp_crit_reg(1);
+temp_crit_reg(2);
+temp_crit_reg(3);
+
+static ssize_t show_analog_out_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+}
+static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->analog_out = DAC_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
+ set_analog_out_reg);
+
+static ssize_t show_vid_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+}
+
+static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
+
+static ssize_t show_vrm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->vrm);
+}
+static ssize_t store_vrm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ data->vrm = simple_strtol(buf, NULL, 10);
+ return count;
+}
+
+static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
+
+static ssize_t show_alarms_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf, "%ld\n", (long) (data->alarms));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
+
+static ssize_t show_alarm_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->alarm_mask);
+}
+static ssize_t set_alarm_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ unsigned long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->alarm_mask = val & 0x7fffffff;
+ mask = data->alarm_mask
+ | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
+ adm1026_write_value(client, ADM1026_REG_MASK1,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK2,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK3,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK4,
+ mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
+ set_alarm_mask);
+
+
+static ssize_t show_gpio(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio);
+}
+static ssize_t set_gpio(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long gpio;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio = val & 0x1ffff;
+ gpio = data->gpio;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+ gpio >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+ gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
+
+
+static ssize_t show_gpio_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio_mask);
+}
+static ssize_t set_gpio_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio_mask = val & 0x1ffff;
+ mask = data->gpio_mask;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+ mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
+
+static ssize_t show_pwm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
+}
+static ssize_t set_pwm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ if (data->pwm1.enable = 1) {
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.pwm = PWM_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ up(&data->update_lock);
+ }
+ return count;
+}
+static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
+}
+static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
+ if (data->pwm1.enable = 2) { /* apply immediately */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
+{
+ return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
+}
+static ssize_t show_pwm_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.enable);
+}
+static ssize_t set_pwm_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ int old_enable;
+
+ if ((val >= 0) && (val < 3)) {
+ down(&data->update_lock);
+ old_enable = data->pwm1.enable;
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.enable = val;
+ data->config1 = (data->config1 & ~CFG1_PWM_AFC)
+ | ((val = 2) ? CFG1_PWM_AFC : 0);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ if (val = 2) { /* apply pwm1_auto_pwm_min to pwm1 */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ } else if (!((old_enable = 1) && (val = 1))) {
+ /* set pwm to safe value */
+ data->pwm1.pwm = 255;
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+/* enable PWM fan control */
+static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+
+static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+
+int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind)
+{
+ int company, verstep;
+ struct i2c_client *new_client;
+ struct adm1026_data *data;
+ int err = 0;
+ const char *type_name = "";
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+ /* We need to be able to do byte I/O */
+ goto exit;
+ };
+
+ /* 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 adm1026_{read,write}_value. */
+
+ if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ memset(data, 0, sizeof(struct adm1026_data));
+
+ new_client = &data->client;
+ i2c_set_clientdata(new_client, data);
+ new_client->addr = address;
+ new_client->adapter = adapter;
+ new_client->driver = &adm1026_driver;
+ new_client->flags = 0;
+
+ /* Now, we do the remaining detection. */
+
+ company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
+ verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
+
+ dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
+ " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
+ i2c_adapter_id(new_client->adapter), new_client->addr,
+ company, verstep);
+
+ /* If auto-detecting, Determine the chip type. */
+ if (kind <= 0) {
+ dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
+ "...\n", i2c_adapter_id(adapter), address);
+ if (company = ADM1026_COMPANY_ANALOG_DEV
+ && verstep = ADM1026_VERSTEP_ADM1026) {
+ kind = adm1026;
+ } else if (company = ADM1026_COMPANY_ANALOG_DEV
+ && (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Unrecognized stepping "
+ "0x%02x. Defaulting to ADM1026.\n", verstep);
+ kind = adm1026;
+ } else if ((verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Found version/stepping "
+ "0x%02x. Assuming generic ADM1026.\n",
+ verstep);
+ kind = any_chip;
+ } else {
+ dev_dbg(&new_client->dev, ": Autodetection "
+ "failed\n");
+ /* Not an ADM1026 ... */
+ if (kind = 0) { /* User used force=x,y */
+ dev_err(&adapter->dev, "Generic ADM1026 not "
+ "found at %d,0x%02x. Try "
+ "force_adm1026.\n",
+ i2c_adapter_id(adapter), address);
+ }
+ err = 0;
+ goto exitfree;
+ }
+ }
+
+ /* Fill in the chip specific driver values */
+ switch (kind) {
+ case any_chip :
+ type_name = "adm1026";
+ break;
+ case adm1026 :
+ type_name = "adm1026";
+ break;
+ default :
+ dev_err(&adapter->dev, ": Internal error, invalid "
+ "kind (%d)!", kind);
+ err = -EFAULT;
+ goto exitfree;
+ }
+ strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
+
+ /* Fill in the remaining client fields */
+ new_client->id = adm1026_id++;
+ data->type = kind;
+ data->valid = 0;
+ init_MUTEX(&data->update_lock);
+
+ dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
+ new_client->id, new_client->id, new_client->name,
+ i2c_adapter_id(new_client->adapter),
+ new_client->addr);
+
+ /* Tell the I2C layer a new client has arrived */
+ if ((err = i2c_attach_client(new_client)))
+ goto exitfree;
+
+ /* Set the VRM version */
+ data->vrm = i2c_which_vrm();
+
+ /* Initialize the ADM1026 chip */
+ adm1026_init_client(new_client);
+
+ /* Register sysfs hooks */
+ device_create_file(&new_client->dev, &dev_attr_in0_input);
+ device_create_file(&new_client->dev, &dev_attr_in0_max);
+ device_create_file(&new_client->dev, &dev_attr_in0_min);
+ device_create_file(&new_client->dev, &dev_attr_in1_input);
+ device_create_file(&new_client->dev, &dev_attr_in1_max);
+ device_create_file(&new_client->dev, &dev_attr_in1_min);
+ device_create_file(&new_client->dev, &dev_attr_in2_input);
+ device_create_file(&new_client->dev, &dev_attr_in2_max);
+ device_create_file(&new_client->dev, &dev_attr_in2_min);
+ device_create_file(&new_client->dev, &dev_attr_in3_input);
+ device_create_file(&new_client->dev, &dev_attr_in3_max);
+ device_create_file(&new_client->dev, &dev_attr_in3_min);
+ device_create_file(&new_client->dev, &dev_attr_in4_input);
+ device_create_file(&new_client->dev, &dev_attr_in4_max);
+ device_create_file(&new_client->dev, &dev_attr_in4_min);
+ device_create_file(&new_client->dev, &dev_attr_in5_input);
+ device_create_file(&new_client->dev, &dev_attr_in5_max);
+ device_create_file(&new_client->dev, &dev_attr_in5_min);
+ device_create_file(&new_client->dev, &dev_attr_in6_input);
+ device_create_file(&new_client->dev, &dev_attr_in6_max);
+ device_create_file(&new_client->dev, &dev_attr_in6_min);
+ device_create_file(&new_client->dev, &dev_attr_in7_input);
+ device_create_file(&new_client->dev, &dev_attr_in7_max);
+ device_create_file(&new_client->dev, &dev_attr_in7_min);
+ device_create_file(&new_client->dev, &dev_attr_in8_input);
+ device_create_file(&new_client->dev, &dev_attr_in8_max);
+ device_create_file(&new_client->dev, &dev_attr_in8_min);
+ device_create_file(&new_client->dev, &dev_attr_in9_input);
+ device_create_file(&new_client->dev, &dev_attr_in9_max);
+ device_create_file(&new_client->dev, &dev_attr_in9_min);
+ device_create_file(&new_client->dev, &dev_attr_in10_input);
+ device_create_file(&new_client->dev, &dev_attr_in10_max);
+ device_create_file(&new_client->dev, &dev_attr_in10_min);
+ device_create_file(&new_client->dev, &dev_attr_in11_input);
+ device_create_file(&new_client->dev, &dev_attr_in11_max);
+ device_create_file(&new_client->dev, &dev_attr_in11_min);
+ device_create_file(&new_client->dev, &dev_attr_in12_input);
+ device_create_file(&new_client->dev, &dev_attr_in12_max);
+ device_create_file(&new_client->dev, &dev_attr_in12_min);
+ device_create_file(&new_client->dev, &dev_attr_in13_input);
+ device_create_file(&new_client->dev, &dev_attr_in13_max);
+ device_create_file(&new_client->dev, &dev_attr_in13_min);
+ device_create_file(&new_client->dev, &dev_attr_in14_input);
+ device_create_file(&new_client->dev, &dev_attr_in14_max);
+ device_create_file(&new_client->dev, &dev_attr_in14_min);
+ device_create_file(&new_client->dev, &dev_attr_in15_input);
+ device_create_file(&new_client->dev, &dev_attr_in15_max);
+ device_create_file(&new_client->dev, &dev_attr_in15_min);
+ device_create_file(&new_client->dev, &dev_attr_in16_input);
+ device_create_file(&new_client->dev, &dev_attr_in16_max);
+ device_create_file(&new_client->dev, &dev_attr_in16_min);
+ device_create_file(&new_client->dev, &dev_attr_fan1_input);
+ device_create_file(&new_client->dev, &dev_attr_fan1_div);
+ device_create_file(&new_client->dev, &dev_attr_fan1_min);
+ device_create_file(&new_client->dev, &dev_attr_fan2_input);
+ device_create_file(&new_client->dev, &dev_attr_fan2_div);
+ device_create_file(&new_client->dev, &dev_attr_fan2_min);
+ device_create_file(&new_client->dev, &dev_attr_fan3_input);
+ device_create_file(&new_client->dev, &dev_attr_fan3_div);
+ device_create_file(&new_client->dev, &dev_attr_fan3_min);
+ device_create_file(&new_client->dev, &dev_attr_fan4_input);
+ device_create_file(&new_client->dev, &dev_attr_fan4_div);
+ device_create_file(&new_client->dev, &dev_attr_fan4_min);
+ device_create_file(&new_client->dev, &dev_attr_fan5_input);
+ device_create_file(&new_client->dev, &dev_attr_fan5_div);
+ device_create_file(&new_client->dev, &dev_attr_fan5_min);
+ device_create_file(&new_client->dev, &dev_attr_fan6_input);
+ device_create_file(&new_client->dev, &dev_attr_fan6_div);
+ device_create_file(&new_client->dev, &dev_attr_fan6_min);
+ device_create_file(&new_client->dev, &dev_attr_fan7_input);
+ device_create_file(&new_client->dev, &dev_attr_fan7_div);
+ device_create_file(&new_client->dev, &dev_attr_fan7_min);
+ device_create_file(&new_client->dev, &dev_attr_fan8_input);
+ device_create_file(&new_client->dev, &dev_attr_fan8_div);
+ device_create_file(&new_client->dev, &dev_attr_fan8_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_input);
+ device_create_file(&new_client->dev, &dev_attr_temp1_max);
+ device_create_file(&new_client->dev, &dev_attr_temp1_min);
+ device_create_file(&new_client->dev, &dev_attr_temp2_input);
+ device_create_file(&new_client->dev, &dev_attr_temp2_max);
+ device_create_file(&new_client->dev, &dev_attr_temp2_min);
+ device_create_file(&new_client->dev, &dev_attr_temp3_input);
+ device_create_file(&new_client->dev, &dev_attr_temp3_max);
+ device_create_file(&new_client->dev, &dev_attr_temp3_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp2_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp3_offset);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point2_temp);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_vid);
+ device_create_file(&new_client->dev, &dev_attr_vrm);
+ device_create_file(&new_client->dev, &dev_attr_alarms);
+ device_create_file(&new_client->dev, &dev_attr_alarm_mask);
+ device_create_file(&new_client->dev, &dev_attr_gpio);
+ device_create_file(&new_client->dev, &dev_attr_gpio_mask);
+ device_create_file(&new_client->dev, &dev_attr_pwm1);
+ device_create_file(&new_client->dev, &dev_attr_pwm2);
+ device_create_file(&new_client->dev, &dev_attr_pwm3);
+ device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_analog_out);
+ return 0;
+
+ /* Error out and cleanup code */
+exitfree:
+ kfree(new_client);
+exit:
+ return err;
+}
+static int __init sm_adm1026_init(void)
+{
+ return i2c_add_driver(&adm1026_driver);
+}
+
+static void __exit sm_adm1026_exit(void)
+{
+ i2c_del_driver(&adm1026_driver);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
+ "Justin Thiessen <jthiessen@penguincomputing.com>");
+MODULE_DESCRIPTION("ADM1026 driver");
+
+module_init(sm_adm1026_init);
+module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: sensors, linux-kernel, Greg KH
> Taking into account Arjan's comments, I have fixed the awkward
> locking constructs. I have also switched from using MODULE_PARM()
> to module_param_array(). As Jean requested (and as I muttonheadedly
> ignored) on the last submission, the diff now includes the patches to
>
> .../drivers/i2c/chips/Makefile
> .../drivers/i2c/chips/Kconfig
Great, looks good enough to me. I'd like to see this patch applied to
the kernel. Any further change can be done through incremental patches,
which are so easier to review.
Thanks Justin for the good work :)
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 [RE-REVISED DRIVER]
@ 2005-05-19 6:25 ` Jean Delvare
0 siblings, 0 replies; 51+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen, Arjan van de Ven; +Cc: LM Sensors, LKML
> > > int adm1026_attach_adapter(struct i2c_adapter *adapter)
> > > {
> > > if (!(adapter->class & I2C_CLASS_HWMON)) {
> > > return 0;
> > > }
> >
> > no need for extra { }'s in such a case
>
> Of course there's no _need_. But I find the result stylistically
> easier to read. Is there any real objection?
There isn't as far as I can tell. The CodingStyle document doesn't
mention a preference for any form or the other, nor does Greg's talk
about coding style. This means that you are free. If anyone wants it the
other way and is brave enough, he/she can submit an incremental patch
for Greg to consider and see how Greg receives it ;)
> > > static ssize_t show_in(struct device *dev, char *buf, int nr)
> > > {
> > > struct adm1026_data *data = adm1026_update_device(dev);
> > > return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
> > > }
> >
> > any chance you could make this use snprintf instead ?
>
> I'll defer to Jean's response...
And I'll defer to Arjan's myself. As said in another post, no other i2c
client driver does use snprintf. If there is no good reason for them to
do (and actually I don't see any) let's stick to sprintf for everyone.
If there is, then we shall fix all drivers, not only adm1026.
Thanks,
--
Jean Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver,
@ 2005-05-19 6:25 ` Greg KH
0 siblings, 0 replies; 51+ messages in thread
From: Greg KH @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: phil, khali, sensors, linux-kernel
Hm, this looks like a bug:
> +static ssize_t set_pwm_enable(struct device *dev, const char *buf,
> + size_t count)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct adm1026_data *data = i2c_get_clientdata(client);
> + int val;
> + int old_enable;
> +
> + if ((val >= 0) && (val < 3)) {
You are using val before assigning it anything. The compiler warns you
about this issue.
Care to fix this up and resend the whole patch?
Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
used :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver,
@ 2005-05-19 6:25 ` Greg KH
0 siblings, 0 replies; 51+ messages in thread
From: Greg KH @ 2005-05-19 6:25 UTC (permalink / raw)
To: Justin Thiessen; +Cc: phil, khali, sensors, linux-kernel
On Wed, Nov 24, 2004 at 03:10:17PM -0800, Justin Thiessen wrote:
> On Wed, Nov 24, 2004 at 01:36:00PM -0800, Greg KH wrote:
> > Hm, this looks like a bug:
>
> <snip egregious stupidity>
>
> > Care to fix this up and resend the whole patch?
>
> Affirmative.
>
> > Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
> > used :)
>
> See below:
Applied, thanks.
Oh, I did make one change:
> +/* Adjust fan_min to account for new fan divisor */
> +void fixup_fan_min(struct device *dev, int fan, int old_div)
This should be static.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 51+ messages in thread
* adm1026 driver port for kernel 2.6.10-rc2 (patch includes
@ 2005-05-19 6:25 ` Justin Thiessen
0 siblings, 0 replies; 51+ messages in thread
From: Justin Thiessen @ 2005-05-19 6:25 UTC (permalink / raw)
To: Greg KH; +Cc: phil, khali, sensors, linux-kernel
On Wed, Nov 24, 2004 at 01:36:00PM -0800, Greg KH wrote:
> Hm, this looks like a bug:
<snip egregious stupidity>
> Care to fix this up and resend the whole patch?
Affirmative.
> Oh, and it should be "Signed-off-by:" not "Signed off by:" like you had
> used :)
See below:
--------------
Hi,
Taking into account Arjan's comments, I have fixed the awkward locking
constructs. I have also switched from using MODULE_PARM() to
module_param_array(). As Jean requested (and as I muttonheadedly ignored)
on the last submission, the diff now includes the patches to
./drivers/i2c/chips/Makefile
./drivers/i2c/chips/Kconfig
Finally (and you've all read this before):
Here is the revised adm1026 driver port for kernel 2.6.10-rc2. It takes into
account Jean Delvare's and Mark Hoffman's comments and recommendations, and
provides pretty much the entire feature set of the 2.4.X kernel driver, but
in (hopefully) a manner compliant with the standards for the 2.6.X kernel
lm_sensors drivers.
As discussed in previous messages, control over the pwm output is provided
via:
pwm[1-3] {0-255}
pwm[1-3]_enable {0-2} (off, manual, automatic fan control)
Note that there is really only one pwm register and one enable bit. pwm[2-3]
and pwm[2-3]_enable are provided for the sake of a chip-indpendent interface,
and are simply RW mirrors of pwm1 and pwm1_enable, respectively.
Access to the DAC is provided via:
analog_out {0-2500} (millivolts)
No way is currently provided to turn on DAC-mediated automatic fan control.
See my previous email in this thread for the reasons why.
Control over automatic fan "on" temperatures are provided by:
temp[1-3]_auto_point1_temp {-128000 - 127000}
Hardware-determined hysteresis and range values are revealed in:
temp[1-3]_auto_point1_temp_hyst {temp[1-3]_auto_point1_temp - 6000}
temp[1-3]_auto_point2_temp {temp[1-3]_auto_point1_temp + 20000}
Failsafe critical temperatures at which the fans go to maximum speed are
controled via:
temp[1-3]_crit_enable {0-1} (off, on)
temp[1-3]_crit {-128000 - 127000}
Again, there is really only one "enable critical-temperature-fan-maximization"
bit. temp[2-3]_crit_enable are simply RW mirrors of temp1_crit_enable
These values override any values set for the pwm-mediated automatic fan
control.
VRM is now set via Rudolf Marek's functions. VID is read from the assumed
correct set of pins (GPIO11-GPIO15), and no longer a user-writable field.
In keeping with Greg KH's changes,
normal_i2c_range
normal_isa_range
have been removed,
and
normal_i2c
has been updated to enumerate all addresses. (Just adding 0x2d)
Finally, the val-comparison-before-assignment bug has been corrected.
Thanks to all for the feedback.
Sincerely,
Justin Thiessen
---------------
jthiessen@penguincomputing.com
Signed-off-by: Justin Thiessen <jthiessen@penguincomputing.com>
----------------
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig linux-2.6.10-rc2/drivers/i2c/chips/Kconfig
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Kconfig 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Kconfig 2004-11-16 17:09:36.000000000 -0800
@@ -32,6 +32,15 @@ config SENSORS_ADM1025
This driver can also be built as a module. If so, the module
will be called adm1025.
+config SENSORS_ADM1026
+ tristate "Analog Devices ADM1026 and compatibles"
+ depends on I2C && EXPERIMENTAL
+ select I2C_SENSOR
+ help
+ If you say yes here you get support for Analog Devices ADM1026
+ This driver can also be built as a module. If so, the module
+ will be called adm1026.
+
config SENSORS_ADM1031
tristate "Analog Devices ADM1031 and compatibles"
depends on I2C && EXPERIMENTAL
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile linux-2.6.10-rc2/drivers/i2c/chips/Makefile
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/Makefile 2004-11-21 21:10:09.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/Makefile 2004-11-16 17:09:10.000000000 -0800
@@ -9,6 +9,7 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
+obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
diff -uprN -X dontdiff linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c
--- linux-2.6.10-rc2-vanilla/drivers/i2c/chips/adm1026.c 1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.10-rc2/drivers/i2c/chips/adm1026.c 2004-11-22 13:14:39.000000000 -0800
@@ -0,0 +1,1779 @@
+/*
+ adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
+ monitoring
+ Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
+ Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
+
+ Chip details at:
+
+ <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
+
+ 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 <linux/config.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c-sensor.h>
+#include <linux/i2c-vid.h>
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
+static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
+
+/* Insmod parameters */
+SENSORS_INSMOD_1(adm1026);
+
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+module_param_array(gpio_input,int,NULL,0);
+MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output,int,NULL,0);
+MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+ "outputs");
+module_param_array(gpio_inverted,int,NULL,0);
+MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+ "inverted");
+module_param_array(gpio_normal,int,NULL,0);
+MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+ "normal/non-inverted");
+module_param_array(gpio_fan,int,NULL,0);
+MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+
+/* Many ADM1026 constants specified below */
+
+/* The ADM1026 registers */
+#define ADM1026_REG_CONFIG1 0x00
+#define CFG1_MONITOR 0x01
+#define CFG1_INT_ENABLE 0x02
+#define CFG1_INT_CLEAR 0x04
+#define CFG1_AIN8_9 0x08
+#define CFG1_THERM_HOT 0x10
+#define CFG1_DAC_AFC 0x20
+#define CFG1_PWM_AFC 0x40
+#define CFG1_RESET 0x80
+#define ADM1026_REG_CONFIG2 0x01
+/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
+#define ADM1026_REG_CONFIG3 0x07
+#define CFG3_GPIO16_ENABLE 0x01
+#define CFG3_CI_CLEAR 0x02
+#define CFG3_VREF_250 0x04
+#define CFG3_GPIO16_DIR 0x40
+#define CFG3_GPIO16_POL 0x80
+#define ADM1026_REG_E2CONFIG 0x13
+#define E2CFG_READ 0x01
+#define E2CFG_WRITE 0x02
+#define E2CFG_ERASE 0x04
+#define E2CFG_ROM 0x08
+#define E2CFG_CLK_EXT 0x80
+
+/* There are 10 general analog inputs and 7 dedicated inputs
+ * They are:
+ * 0 - 9 = AIN0 - AIN9
+ * 10 = Vbat
+ * 11 = 3.3V Standby
+ * 12 = 3.3V Main
+ * 13 = +5V
+ * 14 = Vccp (CPU core voltage)
+ * 15 = +12V
+ * 16 = -12V
+ */
+static u16 ADM1026_REG_IN[] = {
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
+ 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
+ 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
+ };
+static u16 ADM1026_REG_IN_MIN[] = {
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
+ 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
+ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+ };
+static u16 ADM1026_REG_IN_MAX[] = {
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
+ 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
+ 0x43, 0x44, 0x45, 0x46, 0x47
+ };
+
+/* Temperatures are:
+ * 0 - Internal
+ * 1 - External 1
+ * 2 - External 2
+ */
+static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
+static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
+static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
+static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
+static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
+static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
+
+#define ADM1026_REG_FAN(nr) (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3 0x02
+#define ADM1026_REG_FAN_DIV_4_7 0x03
+
+#define ADM1026_REG_DAC 0x04
+#define ADM1026_REG_PWM 0x05
+
+#define ADM1026_REG_GPIO_CFG_0_3 0x08
+#define ADM1026_REG_GPIO_CFG_4_7 0x09
+#define ADM1026_REG_GPIO_CFG_8_11 0x0a
+#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+/* CFG_16 in REG_CFG3 */
+#define ADM1026_REG_GPIO_STATUS_0_7 0x24
+#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+/* STATUS_16 in REG_STATUS4 */
+#define ADM1026_REG_GPIO_MASK_0_7 0x1c
+#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+/* MASK_16 in REG_MASK4 */
+
+#define ADM1026_REG_COMPANY 0x16
+#define ADM1026_REG_VERSTEP 0x17
+/* These are the recognized values for the above regs */
+#define ADM1026_COMPANY_ANALOG_DEV 0x41
+#define ADM1026_VERSTEP_GENERIC 0x40
+#define ADM1026_VERSTEP_ADM1026 0x44
+
+#define ADM1026_REG_MASK1 0x18
+#define ADM1026_REG_MASK2 0x19
+#define ADM1026_REG_MASK3 0x1a
+#define ADM1026_REG_MASK4 0x1b
+
+#define ADM1026_REG_STATUS1 0x20
+#define ADM1026_REG_STATUS2 0x21
+#define ADM1026_REG_STATUS3 0x22
+#define ADM1026_REG_STATUS4 0x23
+
+#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX 255
+
+/* 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.
+ */
+
+/* IN are scaled acording to built-in resistors. These are the
+ * voltages corresponding to 3/4 of full scale (192 or 0xc0)
+ * NOTE: The -12V input needs an additional factor to account
+ * for the Vref pullup resistor.
+ * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
+ * = 13875 * 2.50 / 1.875 - 2500
+ * = 16000
+ *
+ * The values in this table are based on Table II, page 15 of the
+ * datasheet.
+ */
+static int adm1026_scaling[] = { /* .001 Volts */
+ 2250, 2250, 2250, 2250, 2250, 2250,
+ 1875, 1875, 1875, 1875, 3000, 3330,
+ 3330, 4995, 2250, 12000, 13875
+ };
+#define NEG12_OFFSET 16000
+#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
+ 0,255))
+#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+
+/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
+ * and we assume a 2 pulse-per-rev fan tach signal
+ * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) = 1350000
+ */
+#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
+ (div)),1,254))
+#define FAN_FROM_REG(val,div) ((val)=0?-1:(val)=0xff ? 0 : 1350000/((val)*\
+ (div)))
+#define DIV_FROM_REG(val) (1<<(val))
+#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+
+/* Temperature is reported in 1 degC increments */
+#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define TEMP_FROM_REG(val) ((val) * 1000)
+#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
+ -127,127))
+#define OFFSET_FROM_REG(val) ((val) * 1000)
+
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_FROM_REG(val) (val)
+
+#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
+#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
+
+/* Analog output is a voltage, and scaled to millivolts. The datasheet
+ * indicates that the DAC could be used to drive the fans, but in our
+ * example board (Arima HDAMA) it isn't connected to the fans at all.
+ */
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
+#define DAC_FROM_REG(val) (((val)*2500)/255)
+
+/* Typically used with systems using a v9.1 VRM spec ? */
+#define ADM1026_INIT_VRM 91
+
+/* Chip sampling rates
+ *
+ * Some sensors are not updated more frequently than once per second
+ * so it doesn't make sense to read them more often than that.
+ * We cache the results and return the saved data if the driver
+ * is called again before a second has elapsed.
+ *
+ * Also, there is significant configuration data for this chip
+ * So, we keep the config data up to date in the cache
+ * when it is written and only sample it once every 5 *minutes*
+ */
+#define ADM1026_DATA_INTERVAL (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
+
+/* We allow for multiple chips in a single system.
+ *
+ * For each registered ADM1026, we need to keep state information
+ * at client->data. The adm1026_data structure is dynamically
+ * allocated, when a new client structure is allocated. */
+
+struct pwm_data {
+ u8 pwm;
+ u8 enable;
+ u8 auto_pwm_min;
+};
+
+struct adm1026_data {
+ struct i2c_client client;
+ struct semaphore lock;
+ enum chips type;
+
+ struct semaphore update_lock;
+ int valid; /* !=0 if following fields are valid */
+ unsigned long last_reading; /* In jiffies */
+ unsigned long last_config; /* In jiffies */
+
+ u8 in[17]; /* Register value */
+ u8 in_max[17]; /* Register value */
+ u8 in_min[17]; /* Register value */
+ s8 temp[3]; /* Register value */
+ s8 temp_min[3]; /* Register value */
+ s8 temp_max[3]; /* Register value */
+ s8 temp_tmin[3]; /* Register value */
+ s8 temp_crit[3]; /* Register value */
+ s8 temp_offset[3]; /* Register value */
+ u8 fan[8]; /* Register value */
+ u8 fan_min[8]; /* Register value */
+ u8 fan_div[8]; /* Decoded value */
+ struct pwm_data pwm1; /* Pwm control values */
+ int vid; /* Decoded value */
+ u8 vrm; /* VRM version */
+ u8 analog_out; /* Register value (DAC) */
+ long alarms; /* Register encoding, combined */
+ long alarm_mask; /* Register encoding, combined */
+ long gpio; /* Register encoding, combined */
+ long gpio_mask; /* Register encoding, combined */
+ u8 gpio_config[17]; /* Decoded value */
+ u8 config1; /* Register value */
+ u8 config2; /* Register value */
+ u8 config3; /* Register value */
+};
+
+static int adm1026_attach_adapter(struct i2c_adapter *adapter);
+static int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind);
+static int adm1026_detach_client(struct i2c_client *client);
+static int adm1026_read_value(struct i2c_client *client, u8 register);
+static int adm1026_write_value(struct i2c_client *client, u8 register,
+ int value);
+static void adm1026_print_gpio(struct i2c_client *client);
+static void adm1026_fixup_gpio(struct i2c_client *client);
+static struct adm1026_data *adm1026_update_device(struct device *dev);
+static void adm1026_init_client(struct i2c_client *client);
+
+
+static struct i2c_driver adm1026_driver = {
+ .owner = THIS_MODULE,
+ .name = "adm1026",
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = adm1026_attach_adapter,
+ .detach_client = adm1026_detach_client,
+};
+
+static int adm1026_id;
+
+int adm1026_attach_adapter(struct i2c_adapter *adapter)
+{
+ if (!(adapter->class & I2C_CLASS_HWMON)) {
+ return 0;
+ }
+ return i2c_detect(adapter, &addr_data, adm1026_detect);
+}
+
+int adm1026_detach_client(struct i2c_client *client)
+{
+ i2c_detach_client(client);
+ kfree(client);
+ return 0;
+}
+
+int adm1026_read_value(struct i2c_client *client, u8 reg)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_read_byte_data(client, reg) & 0xff;
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
+{
+ int res;
+
+ if (reg < 0x80) {
+ /* "RAM" locations */
+ res = i2c_smbus_write_byte_data(client, reg, value);
+ } else {
+ /* EEPROM, do nothing */
+ res = 0;
+ }
+ return res;
+}
+
+void adm1026_init_client(struct i2c_client *client)
+{
+ int value, i;
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ dev_dbg(&client->dev,"(%d): Initializing device\n", client->id);
+ /* Read chip config */
+ data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
+
+ /* Inform user of chip config */
+ dev_dbg(&client->dev, "(%d): ADM1026_REG_CONFIG1 is: 0x%02x\n",
+ client->id, data->config1);
+ if ((data->config1 & CFG1_MONITOR) = 0) {
+ dev_dbg(&client->dev, "(%d): Monitoring not currently "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_INT_ENABLE) {
+ dev_dbg(&client->dev, "(%d): SMBALERT interrupts are "
+ "enabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_AIN8_9) {
+ dev_dbg(&client->dev, "(%d): in8 and in9 enabled. "
+ "temp3 disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): temp3 enabled. in8 and "
+ "in9 disabled.\n", client->id);
+ }
+ if (data->config1 & CFG1_THERM_HOT) {
+ dev_dbg(&client->dev, "(%d): Automatic THERM, PWM, "
+ "and temp limits enabled.\n", client->id);
+ }
+
+ value = data->config3;
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "(%d): GPIO16 enabled. THERM"
+ "pin disabled.\n", client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): THERM pin enabled. "
+ "GPIO16 disabled.\n", client->id);
+ }
+ if (data->config3 & CFG3_VREF_250) {
+ dev_dbg(&client->dev, "(%d): Vref is 2.50 Volts.\n",
+ client->id);
+ } else {
+ dev_dbg(&client->dev, "(%d): Vref is 1.82 Volts.\n",
+ client->id);
+ }
+ /* Read and pick apart the existing GPIO configuration */
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) = 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ /* ... and then print it */
+ adm1026_print_gpio(client);
+
+ /* If the user asks us to reprogram the GPIO config, then
+ * do it now. But only if this is the first ADM1026.
+ */
+ if (client->id = 0
+ && (gpio_input[0] != -1 || gpio_output[0] != -1
+ || gpio_inverted[0] != -1 || gpio_normal[0] != -1
+ || gpio_fan[0] != -1)) {
+ adm1026_fixup_gpio(client);
+ }
+
+ /* WE INTENTIONALLY make no changes to the limits,
+ * offsets, pwms, fans and zones. If they were
+ * configured, we don't want to mess with them.
+ * If they weren't, the default is 100% PWM, no
+ * control and will suffice until 'sensors -s'
+ * can be run by the user. We DO set the default
+ * value for pwm1.auto_pwm_min to its maximum
+ * so that enabling automatic pwm fan control
+ * without first setting a value for pwm1.auto_pwm_min
+ * will not result in potentially dangerous fan speed decrease.
+ */
+ data->pwm1.auto_pwm_min%5;
+ /* Start monitoring */
+ value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
+ /* Set MONITOR, clear interrupt acknowledge and s/w reset */
+ value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
+ dev_dbg(&client->dev, "(%d): Setting CONFIG to: 0x%02x\n",
+ client->id, value);
+ data->config1 = value;
+ adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
+}
+
+void adm1026_print_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+
+ dev_dbg(&client->dev, "(%d): GPIO config is:",
+ client->id);
+ for (i = 0;i <= 7;++i) {
+ if (data->config2 & (1 << i)) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ } else {
+ dev_dbg(&client->dev, "\t(%d): FAN%d\n",
+ client->id, i);
+ }
+ }
+ for (i = 8;i <= 15;++i) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s%d\n", client->id,
+ data->gpio_config[i] & 0x02 ? "" : "!",
+ data->gpio_config[i] & 0x01 ? "OUT" : "IN",
+ i);
+ }
+ if (data->config3 & CFG3_GPIO16_ENABLE) {
+ dev_dbg(&client->dev, "\t(%d): %sGP%s16\n", client->id,
+ data->gpio_config[16] & 0x02 ? "" : "!",
+ data->gpio_config[16] & 0x01 ? "OUT" : "IN");
+ } else {
+ /* GPIO16 is THERM */
+ dev_dbg(&client->dev, "\t(%d): THERM\n", client->id);
+ }
+}
+
+void adm1026_fixup_gpio(struct i2c_client *client)
+{
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ int value;
+
+ /* Make the changes requested. */
+ /* We may need to unlock/stop monitoring or soft-reset the
+ * chip before we can make changes. This hasn't been
+ * tested much. FIXME
+ */
+
+ /* Make outputs */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
+ data->gpio_config[gpio_output[i]] |= 0x01;
+ }
+ /* if GPIO0-7 is output, it isn't a FAN tach */
+ if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
+ data->config2 |= 1 << gpio_output[i];
+ }
+ }
+
+ /* Input overrides output */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
+ data->gpio_config[gpio_input[i]] &= ~ 0x01;
+ }
+ /* if GPIO0-7 is input, it isn't a FAN tach */
+ if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
+ data->config2 |= 1 << gpio_input[i];
+ }
+ }
+
+ /* Inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
+ data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
+ }
+ }
+
+ /* Normal overrides inverted */
+ for (i = 0;i <= 16;++i) {
+ if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
+ data->gpio_config[gpio_normal[i]] |= 0x02;
+ }
+ }
+
+ /* Fan overrides input and output */
+ for (i = 0;i <= 7;++i) {
+ if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
+ data->config2 &= ~(1 << gpio_fan[i]);
+ }
+ }
+
+ /* Write new configs to registers */
+ adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
+ data->config3 = (data->config3 & 0x3f)
+ | ((data->gpio_config[16] & 0x03) << 6);
+ adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
+ for (i = 15, value = 0;i >= 0;--i) {
+ value <<= 2;
+ value |= data->gpio_config[i] & 0x03;
+ if ((i & 0x03) = 0) {
+ adm1026_write_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4,
+ value);
+ value = 0;
+ }
+ }
+
+ /* Print the new config */
+ adm1026_print_gpio(client);
+}
+
+
+static struct adm1026_data *adm1026_update_device(struct device *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int i;
+ long value, alarms, gpio;
+
+ down(&data->update_lock);
+ if (!data->valid
+ || (jiffies - data->last_reading > ADM1026_DATA_INTERVAL)) {
+ /* Things that change quickly */
+ dev_dbg(&client->dev,"(%d): Reading sensor values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in[i] + adm1026_read_value(client, ADM1026_REG_IN[i]);
+ }
+
+ for (i = 0;i <= 7;++i) {
+ data->fan[i] + adm1026_read_value(client, ADM1026_REG_FAN(i));
+ }
+
+ for (i = 0;i <= 2;++i) {
+ /* NOTE: temp[] is s8 and we assume 2's complement
+ * "conversion" in the assignment */
+ data->temp[i] + adm1026_read_value(client, ADM1026_REG_TEMP[i]);
+ }
+
+ data->pwm1.pwm = adm1026_read_value(client,
+ ADM1026_REG_PWM);
+ data->analog_out = adm1026_read_value(client,
+ ADM1026_REG_DAC);
+ /* GPIO16 is MSbit of alarms, move it to gpio */
+ alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms &= 0x7f;
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
+ data->alarms = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_STATUS_0_7);
+ data->gpio = gpio;
+
+ data->last_reading = jiffies;
+ }; /* last_reading */
+
+ if (!data->valid || (jiffies - data->last_config >
+ ADM1026_CONFIG_INTERVAL)) {
+ /* Things that don't change often */
+ dev_dbg(&client->dev, "(%d): Reading config values\n",
+ client->id);
+ for (i = 0;i <= 16;++i) {
+ data->in_min[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MIN[i]);
+ data->in_max[i] = adm1026_read_value(client,
+ ADM1026_REG_IN_MAX[i]);
+ }
+
+ value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
+ | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
+ << 8);
+ for (i = 0;i <= 7;++i) {
+ data->fan_min[i] = adm1026_read_value(client,
+ ADM1026_REG_FAN_MIN(i));
+ data->fan_div[i] = DIV_FROM_REG(value & 0x03);
+ value >>= 2;
+ }
+
+ for (i = 0; i <= 2; ++i) {
+ /* NOTE: temp_xxx[] are s8 and we assume 2's
+ * complement "conversion" in the assignment
+ */
+ data->temp_min[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MIN[i]);
+ data->temp_max[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_MAX[i]);
+ data->temp_tmin[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_TMIN[i]);
+ data->temp_crit[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_THERM[i]);
+ data->temp_offset[i] = adm1026_read_value(client,
+ ADM1026_REG_TEMP_OFFSET[i]);
+ }
+
+ /* Read the STATUS/alarm masks */
+ alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+ gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+ alarms = (alarms & 0x7f) << 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
+ alarms <<= 8;
+ alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
+ data->alarm_mask = alarms;
+
+ /* Read the GPIO values */
+ gpio |= adm1026_read_value(client,
+ ADM1026_REG_GPIO_MASK_8_15);
+ gpio <<= 8;
+ gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
+ data->gpio_mask = gpio;
+
+ /* Read various values from CONFIG1 */
+ data->config1 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG1);
+ if (data->config1 & CFG1_PWM_AFC) {
+ data->pwm1.enable = 2;
+ data->pwm1.auto_pwm_min =
+ PWM_MIN_FROM_REG(data->pwm1.pwm);
+ }
+ /* Read the GPIO config */
+ data->config2 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG2);
+ data->config3 = adm1026_read_value(client,
+ ADM1026_REG_CONFIG3);
+ data->gpio_config[16] = (data->config3 >> 6) & 0x03;
+
+ value = 0;
+ for (i = 0;i <= 15;++i) {
+ if ((i & 0x03) = 0) {
+ value = adm1026_read_value(client,
+ ADM1026_REG_GPIO_CFG_0_3 + i/4);
+ }
+ data->gpio_config[i] = value & 0x03;
+ value >>= 2;
+ }
+
+ data->last_config = jiffies;
+ }; /* last_config */
+
+ dev_dbg(&client->dev, "(%d): Setting VID from GPIO11-15.\n",
+ client->id);
+ data->vid = (data->gpio >> 11) & 0x1f;
+ data->valid = 1;
+ up(&data->update_lock);
+ return data;
+}
+
+static ssize_t show_in(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+}
+static ssize_t show_in_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+}
+static ssize_t set_in_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+}
+static ssize_t set_in_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[nr] = INS_TO_REG(nr, val);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define in_reg(offset) \
+static ssize_t show_in##offset (struct device *dev, char *buf) \
+{ \
+ return show_in(dev, buf, offset); \
+} \
+static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_in_min(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_min(dev, buf, count, offset); \
+} \
+static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_in_max(dev, buf, offset); \
+} \
+static ssize_t set_in##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_in_max(dev, buf, count, offset); \
+} \
+static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
+static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
+ show_in##offset##_min, set_in##offset##_min); \
+static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
+ show_in##offset##_max, set_in##offset##_max);
+
+
+in_reg(0);
+in_reg(1);
+in_reg(2);
+in_reg(3);
+in_reg(4);
+in_reg(5);
+in_reg(6);
+in_reg(7);
+in_reg(8);
+in_reg(9);
+in_reg(10);
+in_reg(11);
+in_reg(12);
+in_reg(13);
+in_reg(14);
+in_reg(15);
+
+static ssize_t show_in16(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+ NEG12_OFFSET);
+}
+static ssize_t show_in16_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_in16_max(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+ - NEG12_OFFSET);
+}
+static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
+ adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
+static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
+static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
+
+
+
+
+/* Now add fan read/write functions */
+
+static ssize_t show_fan(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+ data->fan_div[nr]));
+}
+static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+ data->fan_div[nr]));
+}
+static ssize_t set_fan_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
+ data->fan_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset(offset) \
+static ssize_t show_fan_##offset (struct device *dev, char *buf) \
+{ \
+ return show_fan(dev, buf, offset - 1); \
+} \
+static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_fan_min(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_min(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
+static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_min, set_fan_##offset##_min);
+
+fan_offset(1);
+fan_offset(2);
+fan_offset(3);
+fan_offset(4);
+fan_offset(5);
+fan_offset(6);
+fan_offset(7);
+fan_offset(8);
+
+/* Adjust fan_min to account for new fan divisor */
+void fixup_fan_min(struct device *dev, int fan, int old_div)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int new_min;
+ int new_div = data->fan_div[fan];
+
+ /* 0 and 0xff are special. Don't adjust them */
+ if (data->fan_min[fan] = 0 || data->fan_min[fan] = 0xff) {
+ return;
+ }
+
+ new_min = data->fan_min[fan] * old_div / new_div;
+ new_min = SENSORS_LIMIT(new_min, 1, 254);
+ data->fan_min[fan] = new_min;
+ adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
+}
+
+/* Now add fan_div read/write functions */
+static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->fan_div[nr]);
+}
+static ssize_t set_fan_div(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val,orig_div,new_div,shift;
+
+ val = simple_strtol(buf, NULL, 10);
+ new_div = DIV_TO_REG(val);
+ if (new_div = 0) {
+ return -EINVAL;
+ }
+ down(&data->update_lock);
+ orig_div = data->fan_div[nr];
+ data->fan_div[nr] = DIV_FROM_REG(new_div);
+
+ if (nr < 4) { /* 0 <= nr < 4 */
+ shift = 2 * nr;
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
+ (new_div << shift)));
+ } else { /* 3 < nr < 8 */
+ shift = 2 * (nr - 4);
+ adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
+ ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
+ (new_div << shift)));
+ }
+
+ if (data->fan_div[nr] != orig_div) {
+ fixup_fan_min(dev,nr,orig_div);
+ }
+ up(&data->update_lock);
+ return count;
+}
+
+#define fan_offset_div(offset) \
+static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
+{ \
+ return show_fan_div(dev, buf, offset - 1); \
+} \
+static ssize_t set_fan_##offset##_div (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_fan_div(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
+ show_fan_##offset##_div, set_fan_##offset##_div);
+
+fan_offset_div(1);
+fan_offset_div(2);
+fan_offset_div(3);
+fan_offset_div(4);
+fan_offset_div(5);
+fan_offset_div(6);
+fan_offset_div(7);
+fan_offset_div(8);
+
+/* Temps */
+static ssize_t show_temp(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+}
+static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+}
+static ssize_t set_temp_min(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_min[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
+ data->temp_min[nr]);
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+}
+static ssize_t set_temp_max(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_max[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
+ data->temp_max[nr]);
+ up(&data->update_lock);
+ return count;
+}
+#define temp_reg(offset) \
+static ssize_t show_temp_##offset (struct device *dev, char *buf) \
+{ \
+ return show_temp(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
+{ \
+ return show_temp_min(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
+{ \
+ return show_temp_max(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_min (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_min(dev, buf, count, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_max (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_max(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
+static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_min, set_temp_##offset##_min); \
+static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_max, set_temp_##offset##_max);
+
+
+temp_reg(1);
+temp_reg(2);
+temp_reg(3);
+
+static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+}
+static ssize_t set_temp_offset(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_offset[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
+ data->temp_offset[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_offset_reg(offset) \
+static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
+{ \
+ return show_temp_offset(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_offset (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_offset(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_offset, set_temp_##offset##_offset);
+
+temp_offset_reg(1);
+temp_offset_reg(2);
+temp_offset_reg(3);
+
+static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(
+ ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
+}
+static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+ ADM1026_FAN_CONTROL_TEMP_RANGE));
+}
+static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
+ int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+}
+static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_tmin[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
+ data->temp_tmin[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_auto_point(offset) \
+static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point1_temp(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
+ *dev, char *buf) \
+{ \
+ return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
+} \
+static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
+ char *buf) \
+{ \
+ return show_temp_auto_point2_temp(dev, buf, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
+ show_temp##offset##_auto_point1_temp, \
+ set_temp##offset##_auto_point1_temp); \
+static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
+ show_temp##offset##_auto_point1_temp_hyst, NULL); \
+static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
+ show_temp##offset##_auto_point2_temp, NULL);
+
+temp_auto_point(1);
+temp_auto_point(2);
+temp_auto_point(3);
+
+static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+}
+static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val = 1) || (val=0)) {
+ down(&data->update_lock);
+ data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
+ show_temp_crit_enable, set_temp_crit_enable);
+
+
+static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+}
+static ssize_t set_temp_crit(struct device *dev, const char *buf,
+ size_t count, int nr)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->temp_crit[nr] = TEMP_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
+ data->temp_crit[nr]);
+ up(&data->update_lock);
+ return count;
+}
+
+#define temp_crit_reg(offset) \
+static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
+{ \
+ return show_temp_crit(dev, buf, offset - 1); \
+} \
+static ssize_t set_temp_##offset##_crit (struct device *dev, \
+ const char *buf, size_t count) \
+{ \
+ return set_temp_crit(dev, buf, count, offset - 1); \
+} \
+static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
+ show_temp_##offset##_crit, set_temp_##offset##_crit);
+
+temp_crit_reg(1);
+temp_crit_reg(2);
+temp_crit_reg(3);
+
+static ssize_t show_analog_out_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+}
+static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->analog_out = DAC_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
+ set_analog_out_reg);
+
+static ssize_t show_vid_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+}
+
+static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
+
+static ssize_t show_vrm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->vrm);
+}
+static ssize_t store_vrm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+
+ data->vrm = simple_strtol(buf, NULL, 10);
+ return count;
+}
+
+static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
+
+static ssize_t show_alarms_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf, "%ld\n", (long) (data->alarms));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
+
+static ssize_t show_alarm_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->alarm_mask);
+}
+static ssize_t set_alarm_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ unsigned long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->alarm_mask = val & 0x7fffffff;
+ mask = data->alarm_mask
+ | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
+ adm1026_write_value(client, ADM1026_REG_MASK1,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK2,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK3,
+ mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_MASK4,
+ mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
+ set_alarm_mask);
+
+
+static ssize_t show_gpio(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio);
+}
+static ssize_t set_gpio(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long gpio;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio = val & 0x1ffff;
+ gpio = data->gpio;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+ gpio >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+ gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
+
+
+static ssize_t show_gpio_mask(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%ld\n", data->gpio_mask);
+}
+static ssize_t set_gpio_mask(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ long mask;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->gpio_mask = val & 0x1ffff;
+ mask = data->gpio_mask;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+ mask >>= 8;
+ adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+ mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
+ adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+ up(&data->update_lock);
+ return count;
+}
+
+static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
+
+static ssize_t show_pwm_reg(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
+}
+static ssize_t set_pwm_reg(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ if (data->pwm1.enable = 1) {
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.pwm = PWM_TO_REG(val);
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ up(&data->update_lock);
+ }
+ return count;
+}
+static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
+}
+static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+
+ down(&data->update_lock);
+ val = simple_strtol(buf, NULL, 10);
+ data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
+ if (data->pwm1.enable = 2) { /* apply immediately */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ return count;
+}
+static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
+{
+ return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
+}
+static ssize_t show_pwm_enable(struct device *dev, char *buf)
+{
+ struct adm1026_data *data = adm1026_update_device(dev);
+ return sprintf(buf,"%d\n", data->pwm1.enable);
+}
+static ssize_t set_pwm_enable(struct device *dev, const char *buf,
+ size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct adm1026_data *data = i2c_get_clientdata(client);
+ int val;
+ int old_enable;
+
+ val = simple_strtol(buf, NULL, 10);
+ if ((val >= 0) && (val < 3)) {
+ down(&data->update_lock);
+ old_enable = data->pwm1.enable;
+ data->pwm1.enable = val;
+ data->config1 = (data->config1 & ~CFG1_PWM_AFC)
+ | ((val = 2) ? CFG1_PWM_AFC : 0);
+ adm1026_write_value(client, ADM1026_REG_CONFIG1,
+ data->config1);
+ if (val = 2) { /* apply pwm1_auto_pwm_min to pwm1 */
+ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
+ PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ } else if (!((old_enable = 1) && (val = 1))) {
+ /* set pwm to safe value */
+ data->pwm1.pwm = 255;
+ adm1026_write_value(client, ADM1026_REG_PWM,
+ data->pwm1.pwm);
+ }
+ up(&data->update_lock);
+ }
+ return count;
+}
+
+/* enable PWM fan control */
+static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
+ set_pwm_enable);
+static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_auto_pwm_min, set_auto_pwm_min);
+
+static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
+
+int adm1026_detect(struct i2c_adapter *adapter, int address,
+ int kind)
+{
+ int company, verstep;
+ struct i2c_client *new_client;
+ struct adm1026_data *data;
+ int err = 0;
+ const char *type_name = "";
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+ /* We need to be able to do byte I/O */
+ goto exit;
+ };
+
+ /* 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 adm1026_{read,write}_value. */
+
+ if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ memset(data, 0, sizeof(struct adm1026_data));
+
+ new_client = &data->client;
+ i2c_set_clientdata(new_client, data);
+ new_client->addr = address;
+ new_client->adapter = adapter;
+ new_client->driver = &adm1026_driver;
+ new_client->flags = 0;
+
+ /* Now, we do the remaining detection. */
+
+ company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
+ verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
+
+ dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
+ " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
+ i2c_adapter_id(new_client->adapter), new_client->addr,
+ company, verstep);
+
+ /* If auto-detecting, Determine the chip type. */
+ if (kind <= 0) {
+ dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
+ "...\n", i2c_adapter_id(adapter), address);
+ if (company = ADM1026_COMPANY_ANALOG_DEV
+ && verstep = ADM1026_VERSTEP_ADM1026) {
+ kind = adm1026;
+ } else if (company = ADM1026_COMPANY_ANALOG_DEV
+ && (verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Unrecognized stepping "
+ "0x%02x. Defaulting to ADM1026.\n", verstep);
+ kind = adm1026;
+ } else if ((verstep & 0xf0) = ADM1026_VERSTEP_GENERIC) {
+ dev_err(&adapter->dev, ": Found version/stepping "
+ "0x%02x. Assuming generic ADM1026.\n",
+ verstep);
+ kind = any_chip;
+ } else {
+ dev_dbg(&new_client->dev, ": Autodetection "
+ "failed\n");
+ /* Not an ADM1026 ... */
+ if (kind = 0) { /* User used force=x,y */
+ dev_err(&adapter->dev, "Generic ADM1026 not "
+ "found at %d,0x%02x. Try "
+ "force_adm1026.\n",
+ i2c_adapter_id(adapter), address);
+ }
+ err = 0;
+ goto exitfree;
+ }
+ }
+
+ /* Fill in the chip specific driver values */
+ switch (kind) {
+ case any_chip :
+ type_name = "adm1026";
+ break;
+ case adm1026 :
+ type_name = "adm1026";
+ break;
+ default :
+ dev_err(&adapter->dev, ": Internal error, invalid "
+ "kind (%d)!", kind);
+ err = -EFAULT;
+ goto exitfree;
+ }
+ strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
+
+ /* Fill in the remaining client fields */
+ new_client->id = adm1026_id++;
+ data->type = kind;
+ data->valid = 0;
+ init_MUTEX(&data->update_lock);
+
+ dev_dbg(&new_client->dev, "(%d): Assigning ID %d to %s at %d,0x%02x\n",
+ new_client->id, new_client->id, new_client->name,
+ i2c_adapter_id(new_client->adapter),
+ new_client->addr);
+
+ /* Tell the I2C layer a new client has arrived */
+ if ((err = i2c_attach_client(new_client)))
+ goto exitfree;
+
+ /* Set the VRM version */
+ data->vrm = i2c_which_vrm();
+
+ /* Initialize the ADM1026 chip */
+ adm1026_init_client(new_client);
+
+ /* Register sysfs hooks */
+ device_create_file(&new_client->dev, &dev_attr_in0_input);
+ device_create_file(&new_client->dev, &dev_attr_in0_max);
+ device_create_file(&new_client->dev, &dev_attr_in0_min);
+ device_create_file(&new_client->dev, &dev_attr_in1_input);
+ device_create_file(&new_client->dev, &dev_attr_in1_max);
+ device_create_file(&new_client->dev, &dev_attr_in1_min);
+ device_create_file(&new_client->dev, &dev_attr_in2_input);
+ device_create_file(&new_client->dev, &dev_attr_in2_max);
+ device_create_file(&new_client->dev, &dev_attr_in2_min);
+ device_create_file(&new_client->dev, &dev_attr_in3_input);
+ device_create_file(&new_client->dev, &dev_attr_in3_max);
+ device_create_file(&new_client->dev, &dev_attr_in3_min);
+ device_create_file(&new_client->dev, &dev_attr_in4_input);
+ device_create_file(&new_client->dev, &dev_attr_in4_max);
+ device_create_file(&new_client->dev, &dev_attr_in4_min);
+ device_create_file(&new_client->dev, &dev_attr_in5_input);
+ device_create_file(&new_client->dev, &dev_attr_in5_max);
+ device_create_file(&new_client->dev, &dev_attr_in5_min);
+ device_create_file(&new_client->dev, &dev_attr_in6_input);
+ device_create_file(&new_client->dev, &dev_attr_in6_max);
+ device_create_file(&new_client->dev, &dev_attr_in6_min);
+ device_create_file(&new_client->dev, &dev_attr_in7_input);
+ device_create_file(&new_client->dev, &dev_attr_in7_max);
+ device_create_file(&new_client->dev, &dev_attr_in7_min);
+ device_create_file(&new_client->dev, &dev_attr_in8_input);
+ device_create_file(&new_client->dev, &dev_attr_in8_max);
+ device_create_file(&new_client->dev, &dev_attr_in8_min);
+ device_create_file(&new_client->dev, &dev_attr_in9_input);
+ device_create_file(&new_client->dev, &dev_attr_in9_max);
+ device_create_file(&new_client->dev, &dev_attr_in9_min);
+ device_create_file(&new_client->dev, &dev_attr_in10_input);
+ device_create_file(&new_client->dev, &dev_attr_in10_max);
+ device_create_file(&new_client->dev, &dev_attr_in10_min);
+ device_create_file(&new_client->dev, &dev_attr_in11_input);
+ device_create_file(&new_client->dev, &dev_attr_in11_max);
+ device_create_file(&new_client->dev, &dev_attr_in11_min);
+ device_create_file(&new_client->dev, &dev_attr_in12_input);
+ device_create_file(&new_client->dev, &dev_attr_in12_max);
+ device_create_file(&new_client->dev, &dev_attr_in12_min);
+ device_create_file(&new_client->dev, &dev_attr_in13_input);
+ device_create_file(&new_client->dev, &dev_attr_in13_max);
+ device_create_file(&new_client->dev, &dev_attr_in13_min);
+ device_create_file(&new_client->dev, &dev_attr_in14_input);
+ device_create_file(&new_client->dev, &dev_attr_in14_max);
+ device_create_file(&new_client->dev, &dev_attr_in14_min);
+ device_create_file(&new_client->dev, &dev_attr_in15_input);
+ device_create_file(&new_client->dev, &dev_attr_in15_max);
+ device_create_file(&new_client->dev, &dev_attr_in15_min);
+ device_create_file(&new_client->dev, &dev_attr_in16_input);
+ device_create_file(&new_client->dev, &dev_attr_in16_max);
+ device_create_file(&new_client->dev, &dev_attr_in16_min);
+ device_create_file(&new_client->dev, &dev_attr_fan1_input);
+ device_create_file(&new_client->dev, &dev_attr_fan1_div);
+ device_create_file(&new_client->dev, &dev_attr_fan1_min);
+ device_create_file(&new_client->dev, &dev_attr_fan2_input);
+ device_create_file(&new_client->dev, &dev_attr_fan2_div);
+ device_create_file(&new_client->dev, &dev_attr_fan2_min);
+ device_create_file(&new_client->dev, &dev_attr_fan3_input);
+ device_create_file(&new_client->dev, &dev_attr_fan3_div);
+ device_create_file(&new_client->dev, &dev_attr_fan3_min);
+ device_create_file(&new_client->dev, &dev_attr_fan4_input);
+ device_create_file(&new_client->dev, &dev_attr_fan4_div);
+ device_create_file(&new_client->dev, &dev_attr_fan4_min);
+ device_create_file(&new_client->dev, &dev_attr_fan5_input);
+ device_create_file(&new_client->dev, &dev_attr_fan5_div);
+ device_create_file(&new_client->dev, &dev_attr_fan5_min);
+ device_create_file(&new_client->dev, &dev_attr_fan6_input);
+ device_create_file(&new_client->dev, &dev_attr_fan6_div);
+ device_create_file(&new_client->dev, &dev_attr_fan6_min);
+ device_create_file(&new_client->dev, &dev_attr_fan7_input);
+ device_create_file(&new_client->dev, &dev_attr_fan7_div);
+ device_create_file(&new_client->dev, &dev_attr_fan7_min);
+ device_create_file(&new_client->dev, &dev_attr_fan8_input);
+ device_create_file(&new_client->dev, &dev_attr_fan8_div);
+ device_create_file(&new_client->dev, &dev_attr_fan8_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_input);
+ device_create_file(&new_client->dev, &dev_attr_temp1_max);
+ device_create_file(&new_client->dev, &dev_attr_temp1_min);
+ device_create_file(&new_client->dev, &dev_attr_temp2_input);
+ device_create_file(&new_client->dev, &dev_attr_temp2_max);
+ device_create_file(&new_client->dev, &dev_attr_temp2_min);
+ device_create_file(&new_client->dev, &dev_attr_temp3_input);
+ device_create_file(&new_client->dev, &dev_attr_temp3_max);
+ device_create_file(&new_client->dev, &dev_attr_temp3_min);
+ device_create_file(&new_client->dev, &dev_attr_temp1_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp2_offset);
+ device_create_file(&new_client->dev, &dev_attr_temp3_offset);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point1_temp_hyst);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp1_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp2_auto_point2_temp);
+ device_create_file(&new_client->dev,
+ &dev_attr_temp3_auto_point2_temp);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit);
+ device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
+ device_create_file(&new_client->dev, &dev_attr_vid);
+ device_create_file(&new_client->dev, &dev_attr_vrm);
+ device_create_file(&new_client->dev, &dev_attr_alarms);
+ device_create_file(&new_client->dev, &dev_attr_alarm_mask);
+ device_create_file(&new_client->dev, &dev_attr_gpio);
+ device_create_file(&new_client->dev, &dev_attr_gpio_mask);
+ device_create_file(&new_client->dev, &dev_attr_pwm1);
+ device_create_file(&new_client->dev, &dev_attr_pwm2);
+ device_create_file(&new_client->dev, &dev_attr_pwm3);
+ device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
+ device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
+ device_create_file(&new_client->dev, &dev_attr_analog_out);
+ return 0;
+
+ /* Error out and cleanup code */
+exitfree:
+ kfree(new_client);
+exit:
+ return err;
+}
+static int __init sm_adm1026_init(void)
+{
+ return i2c_add_driver(&adm1026_driver);
+}
+
+static void __exit sm_adm1026_exit(void)
+{
+ i2c_del_driver(&adm1026_driver);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
+ "Justin Thiessen <jthiessen@penguincomputing.com>");
+MODULE_DESCRIPTION("ADM1026 driver");
+
+module_init(sm_adm1026_init);
+module_exit(sm_adm1026_exit);
^ permalink raw reply [flat|nested] 51+ messages in thread
end of thread, other threads:[~2005-05-19 6:25 UTC | newest]
Thread overview: 51+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19 6:25 adm1026 driver port for kernel 2.6.X Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
2004-11-02 16:46 ` adm1026 driver port for kernel 2.6.X - [REVISED DRIVER] Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-02 19:31 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-02 22:17 ` Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-03 8:01 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-03 16:43 ` adm1026 driver port for kernel 2.6.X - [RE-REVISED DRIVER] Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-16 18:56 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-18 18:56 ` adm1026 driver port for kernel 2.6.10-rc2 " Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-20 9:57 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-22 19:35 ` Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-20 10:13 ` Arjan van de Ven
2005-05-19 6:25 ` Arjan van de Ven
2004-11-20 10:32 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-22 19:43 ` Justin Thiessen
2005-05-19 6:25 ` Justin Thiessen
2004-11-22 21:00 ` Arjan van de Ven
2005-05-19 6:25 ` Arjan van de Ven
2004-11-22 21:30 ` linux-os
2005-05-19 6:25 ` linux-os
2004-11-23 17:58 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2004-11-23 16:52 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) Justin Thiessen
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Justin Thiessen
2004-11-23 17:50 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) Jean Delvare
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes Jean Delvare
2004-11-24 21:36 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) Greg KH
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Greg KH
2004-11-24 23:10 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) [fixed] Justin Thiessen
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes Justin Thiessen
2004-11-24 22:35 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, patch to Kconfig, and patch to Makefile) [fixed] Greg KH
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.10-rc2 (patch includes driver, Greg KH
2005-05-19 6:25 ` adm1026 driver port for kernel 2.6.X Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Mark M. Hoffman
2005-05-19 6:25 ` Justin Thiessen
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Justin Thiessen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.