Commit 8a0795d9 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

hwmon: (lm85) Support different PWM frequency tables

The Analog Devices and SMSC devices supported by the lm85 driver do
not have the same PWM frequency table as the National Semiconductor
devices. Add support for per-device frequency tables.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarHerbert Poetzl <herbert@13thfloor.at>
parent 86010c98
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
Chip details at <http://www.national.com/ds/LM/LM85.pdf> Chip details at <http://www.national.com/ds/LM/LM85.pdf>
...@@ -192,20 +193,27 @@ static int RANGE_TO_REG(int range) ...@@ -192,20 +193,27 @@ static int RANGE_TO_REG(int range)
/* These are the PWM frequency encodings */ /* These are the PWM frequency encodings */
static const int lm85_freq_map[8] = { /* 1 Hz */ static const int lm85_freq_map[8] = { /* 1 Hz */
10, 15, 23, 30, 38, 47, 62, 94 10, 15, 23, 30, 38, 47, 61, 94
};
static const int adm1027_freq_map[8] = { /* 1 Hz */
11, 15, 22, 29, 35, 44, 59, 88
}; };
static int FREQ_TO_REG(int freq) static int FREQ_TO_REG(const int *map, int freq)
{ {
int i; int i;
/* Find the closest match */ /* Find the closest match */
for (i = 0; i < 7; ++i) for (i = 0; i < 7; ++i)
if (freq <= (lm85_freq_map[i] + lm85_freq_map[i + 1]) / 2) if (freq <= (map[i] + map[i + 1]) / 2)
break; break;
return i; return i;
} }
#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07]
static int FREQ_FROM_REG(const int *map, u8 reg)
{
return map[reg & 0x07];
}
/* Since we can't use strings, I'm abusing these numbers /* Since we can't use strings, I'm abusing these numbers
* to stand in for the following meanings: * to stand in for the following meanings:
...@@ -283,6 +291,7 @@ struct lm85_autofan { ...@@ -283,6 +291,7 @@ struct lm85_autofan {
struct lm85_data { struct lm85_data {
struct i2c_client client; struct i2c_client client;
struct device *hwmon_dev; struct device *hwmon_dev;
const int *freq_map;
enum chips type; enum chips type;
struct mutex update_lock; struct mutex update_lock;
...@@ -532,7 +541,8 @@ static ssize_t show_pwm_freq(struct device *dev, ...@@ -532,7 +541,8 @@ static ssize_t show_pwm_freq(struct device *dev,
{ {
int nr = to_sensor_dev_attr(attr)->index; int nr = to_sensor_dev_attr(attr)->index;
struct lm85_data *data = lm85_update_device(dev); struct lm85_data *data = lm85_update_device(dev);
return sprintf(buf, "%d\n", FREQ_FROM_REG(data->pwm_freq[nr])); return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
data->pwm_freq[nr]));
} }
static ssize_t set_pwm_freq(struct device *dev, static ssize_t set_pwm_freq(struct device *dev,
...@@ -544,7 +554,7 @@ static ssize_t set_pwm_freq(struct device *dev, ...@@ -544,7 +554,7 @@ static ssize_t set_pwm_freq(struct device *dev,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm_freq[nr] = FREQ_TO_REG(val); data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
(data->zone[nr].range << 4) (data->zone[nr].range << 4)
| data->pwm_freq[nr]); | data->pwm_freq[nr]);
...@@ -1184,24 +1194,31 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -1184,24 +1194,31 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
switch (kind) { switch (kind) {
case lm85b: case lm85b:
type_name = "lm85b"; type_name = "lm85b";
data->freq_map = lm85_freq_map;
break; break;
case lm85c: case lm85c:
type_name = "lm85c"; type_name = "lm85c";
data->freq_map = lm85_freq_map;
break; break;
case adm1027: case adm1027:
type_name = "adm1027"; type_name = "adm1027";
data->freq_map = adm1027_freq_map;
break; break;
case adt7463: case adt7463:
type_name = "adt7463"; type_name = "adt7463";
data->freq_map = adm1027_freq_map;
break; break;
case emc6d100: case emc6d100:
type_name = "emc6d100"; type_name = "emc6d100";
data->freq_map = adm1027_freq_map;
break; break;
case emc6d102: case emc6d102:
type_name = "emc6d102"; type_name = "emc6d102";
data->freq_map = adm1027_freq_map;
break; break;
default: default:
type_name = "lm85"; type_name = "lm85";
data->freq_map = lm85_freq_map;
} }
strlcpy(client->name, type_name, I2C_NAME_SIZE); strlcpy(client->name, type_name, I2C_NAME_SIZE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment