aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJuerg Haefliger <juergh@gmail.com>2008-03-26 00:49:15 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2008-07-31 23:44:02 -0400
commitf994fb23d3c63dffc8127f227f3e0c530e3e4fd6 (patch)
tree5e5fd2a862b5f610054d1215914296f46851faf9 /drivers/hwmon
parent92430b6feb19aba043171ff3094535b598052901 (diff)
hwmon: (dme1737) fix voltage scaling
This patch fixes a voltage scaling issue for the sch311x device. Signed-Off-By: Juerg Haefliger <juergh at gmail.com> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/dme1737.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 5a3d41fbdb3c..5e2cf0aef480 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -181,6 +181,7 @@ struct dme1737_data {
181 int valid; /* !=0 if following fields are valid */ 181 int valid; /* !=0 if following fields are valid */
182 unsigned long last_update; /* in jiffies */ 182 unsigned long last_update; /* in jiffies */
183 unsigned long last_vbat; /* in jiffies */ 183 unsigned long last_vbat; /* in jiffies */
184 enum chips type;
184 185
185 u8 vid; 186 u8 vid;
186 u8 pwm_rr_en; 187 u8 pwm_rr_en;
@@ -215,20 +216,27 @@ struct dme1737_data {
215}; 216};
216 217
217/* Nominal voltage values */ 218/* Nominal voltage values */
218static const int IN_NOMINAL[] = {5000, 2250, 3300, 5000, 12000, 3300, 3300}; 219static const int IN_NOMINAL_DME1737[] = {5000, 2250, 3300, 5000, 12000, 3300,
220 3300};
221static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
222 3300};
223#define IN_NOMINAL(ix, type) (((type) == dme1737) ? \
224 IN_NOMINAL_DME1737[(ix)] : \
225 IN_NOMINAL_SCH311x[(ix)])
219 226
220/* Voltage input 227/* Voltage input
221 * Voltage inputs have 16 bits resolution, limit values have 8 bits 228 * Voltage inputs have 16 bits resolution, limit values have 8 bits
222 * resolution. */ 229 * resolution. */
223static inline int IN_FROM_REG(int reg, int ix, int res) 230static inline int IN_FROM_REG(int reg, int ix, int res, int type)
224{ 231{
225 return (reg * IN_NOMINAL[ix] + (3 << (res - 3))) / (3 << (res - 2)); 232 return (reg * IN_NOMINAL(ix, type) + (3 << (res - 3))) /
233 (3 << (res - 2));
226} 234}
227 235
228static inline int IN_TO_REG(int val, int ix) 236static inline int IN_TO_REG(int val, int ix, int type)
229{ 237{
230 return SENSORS_LIMIT((val * 192 + IN_NOMINAL[ix] / 2) / 238 return SENSORS_LIMIT((val * 192 + IN_NOMINAL(ix, type) / 2) /
231 IN_NOMINAL[ix], 0, 255); 239 IN_NOMINAL(ix, type), 0, 255);
232} 240}
233 241
234/* Temperature input 242/* Temperature input
@@ -727,13 +735,13 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
727 735
728 switch (fn) { 736 switch (fn) {
729 case SYS_IN_INPUT: 737 case SYS_IN_INPUT:
730 res = IN_FROM_REG(data->in[ix], ix, 16); 738 res = IN_FROM_REG(data->in[ix], ix, 16, data->type);
731 break; 739 break;
732 case SYS_IN_MIN: 740 case SYS_IN_MIN:
733 res = IN_FROM_REG(data->in_min[ix], ix, 8); 741 res = IN_FROM_REG(data->in_min[ix], ix, 8, data->type);
734 break; 742 break;
735 case SYS_IN_MAX: 743 case SYS_IN_MAX:
736 res = IN_FROM_REG(data->in_max[ix], ix, 8); 744 res = IN_FROM_REG(data->in_max[ix], ix, 8, data->type);
737 break; 745 break;
738 case SYS_IN_ALARM: 746 case SYS_IN_ALARM:
739 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; 747 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01;
@@ -760,12 +768,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
760 mutex_lock(&data->update_lock); 768 mutex_lock(&data->update_lock);
761 switch (fn) { 769 switch (fn) {
762 case SYS_IN_MIN: 770 case SYS_IN_MIN:
763 data->in_min[ix] = IN_TO_REG(val, ix); 771 data->in_min[ix] = IN_TO_REG(val, ix, data->type);
764 dme1737_write(client, DME1737_REG_IN_MIN(ix), 772 dme1737_write(client, DME1737_REG_IN_MIN(ix),
765 data->in_min[ix]); 773 data->in_min[ix]);
766 break; 774 break;
767 case SYS_IN_MAX: 775 case SYS_IN_MAX:
768 data->in_max[ix] = IN_TO_REG(val, ix); 776 data->in_max[ix] = IN_TO_REG(val, ix, data->type);
769 dme1737_write(client, DME1737_REG_IN_MAX(ix), 777 dme1737_write(client, DME1737_REG_IN_MAX(ix),
770 data->in_max[ix]); 778 data->in_max[ix]);
771 break; 779 break;
@@ -2167,6 +2175,7 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2167 2175
2168 kind = dme1737; 2176 kind = dme1737;
2169 name = "dme1737"; 2177 name = "dme1737";
2178 data->type = kind;
2170 2179
2171 /* Fill in the remaining client fields and put it into the global 2180 /* Fill in the remaining client fields and put it into the global
2172 * list */ 2181 * list */
@@ -2359,6 +2368,7 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2359 err = -ENODEV; 2368 err = -ENODEV;
2360 goto exit_kfree; 2369 goto exit_kfree;
2361 } 2370 }
2371 data->type = -1;
2362 2372
2363 /* Fill in the remaining client fields and initialize the mutex */ 2373 /* Fill in the remaining client fields and initialize the mutex */
2364 strlcpy(client->name, "sch311x", I2C_NAME_SIZE); 2374 strlcpy(client->name, "sch311x", I2C_NAME_SIZE);