Commit 57bc3019 authored by Jeremy Gebben's avatar Jeremy Gebben Committed by Guenter Roeck

hwmon: (lm85) remove freq_map size hardcodes

Allow support for chips that support more than 8 frequencies.
Signed-off-by: default avatarJeremy Gebben <jgebben@sweptlaser.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent e2f05d60
...@@ -198,13 +198,13 @@ static int RANGE_TO_REG(long range) ...@@ -198,13 +198,13 @@ static int RANGE_TO_REG(long range)
#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
/* 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[] = { /* 1 Hz */
10, 15, 23, 30, 38, 47, 61, 94 10, 15, 23, 30, 38, 47, 61, 94
}; };
static const int adm1027_freq_map[8] = { /* 1 Hz */
static const int adm1027_freq_map[] = { /* 1 Hz */
11, 15, 22, 29, 35, 44, 59, 88 11, 15, 22, 29, 35, 44, 59, 88
}; };
#define FREQ_MAP_LEN 8
static int FREQ_TO_REG(const int *map, static int FREQ_TO_REG(const int *map,
unsigned int map_size, unsigned long freq) unsigned int map_size, unsigned long freq)
...@@ -212,9 +212,9 @@ static int FREQ_TO_REG(const int *map, ...@@ -212,9 +212,9 @@ static int FREQ_TO_REG(const int *map,
return find_closest(freq, map, map_size); return find_closest(freq, map, map_size);
} }
static int FREQ_FROM_REG(const int *map, u8 reg) static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg)
{ {
return map[reg & 0x07]; return map[reg % map_size];
} }
/* /*
...@@ -296,6 +296,8 @@ struct lm85_data { ...@@ -296,6 +296,8 @@ struct lm85_data {
struct i2c_client *client; struct i2c_client *client;
const struct attribute_group *groups[6]; const struct attribute_group *groups[6];
const int *freq_map; const int *freq_map;
unsigned int freq_map_size;
enum chips type; enum chips type;
bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */ bool has_vid5; /* true if VID5 is configured for ADT7463 or ADT7468 */
...@@ -514,7 +516,7 @@ static struct lm85_data *lm85_update_device(struct device *dev) ...@@ -514,7 +516,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
data->autofan[i].config = data->autofan[i].config =
lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
data->pwm_freq[i] = val & 0x07; data->pwm_freq[i] = val % data->freq_map_size;
data->zone[i].range = val >> 4; data->zone[i].range = val >> 4;
data->autofan[i].min_pwm = data->autofan[i].min_pwm =
lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
...@@ -791,7 +793,8 @@ static ssize_t show_pwm_freq(struct device *dev, ...@@ -791,7 +793,8 @@ static ssize_t show_pwm_freq(struct device *dev,
if (IS_ADT7468_HFPWM(data)) if (IS_ADT7468_HFPWM(data))
freq = 22500; freq = 22500;
else else
freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]); freq = FREQ_FROM_REG(data->freq_map, data->freq_map_size,
data->pwm_freq[nr]);
return sprintf(buf, "%d\n", freq); return sprintf(buf, "%d\n", freq);
} }
...@@ -820,7 +823,7 @@ static ssize_t set_pwm_freq(struct device *dev, ...@@ -820,7 +823,7 @@ static ssize_t set_pwm_freq(struct device *dev,
lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
} else { /* Low freq. mode */ } else { /* Low freq. mode */
data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map,
FREQ_MAP_LEN, val); data->freq_map_size, 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]);
...@@ -1196,7 +1199,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, ...@@ -1196,7 +1199,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev,
TEMP_FROM_REG(data->zone[nr].limit)); TEMP_FROM_REG(data->zone[nr].limit));
lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
((data->zone[nr].range & 0x0f) << 4) ((data->zone[nr].range & 0x0f) << 4)
| (data->pwm_freq[nr] & 0x07)); | data->pwm_freq[nr]);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
...@@ -1232,7 +1235,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, ...@@ -1232,7 +1235,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev,
val - min); val - min);
lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
((data->zone[nr].range & 0x0f) << 4) ((data->zone[nr].range & 0x0f) << 4)
| (data->pwm_freq[nr] & 0x07)); | data->pwm_freq[nr]);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -1569,9 +1572,11 @@ static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1569,9 +1572,11 @@ static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id)
case emc6d103: case emc6d103:
case emc6d103s: case emc6d103s:
data->freq_map = adm1027_freq_map; data->freq_map = adm1027_freq_map;
data->freq_map_size = ARRAY_SIZE(adm1027_freq_map);
break; break;
default: default:
data->freq_map = lm85_freq_map; data->freq_map = lm85_freq_map;
data->freq_map_size = ARRAY_SIZE(lm85_freq_map);
} }
/* Set the VRM version */ /* Set the VRM version */
......
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