From bb33d50c0e3b1d8e6bdd3f5a7427117dafde9bcb Mon Sep 17 00:00:00 2001 From: "Mark D. Studebaker" Date: Sun, 16 May 2004 14:19:57 +0000 Subject: [PATCH] Many PWM fixes: Fix enable; implement disable; preserve clock select bit; /proc value now 0-255; use correct bits in register git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2536 7894878c-1315-0410-8ee3-d5d059ff63e0 --- kernel/chips/smsc47m1.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/kernel/chips/smsc47m1.c b/kernel/chips/smsc47m1.c index 11574277..4e22414b 100644 --- a/kernel/chips/smsc47m1.c +++ b/kernel/chips/smsc47m1.c @@ -117,8 +117,9 @@ static inline u8 MIN_TO_REG(long rpm, int div) 983040/(((val)-preload)*(div))) #define DIV_FROM_REG(val) (1 << (val)) #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) -#define PWM_FROM_REG(val) ((((val) & 0x7f) * 1005) / 640) -#define PWM_TO_REG(val) SENSORS_LIMIT((((val) * 645) / 1000), 0, 63) +/* reg is 6 middle bits; /proc is 8 bits */ +#define PWM_FROM_REG(val) (((val) << 1) & 0xfc) +#define PWM_TO_REG(val) (((SENSORS_LIMIT((val), 0, 255)) >> 1) & 0x7e) struct smsc47m1_data { struct i2c_client client; @@ -458,22 +459,27 @@ void smsc47m1_pwm(struct i2c_client *client, int operation, int ctl_name, else if (operation == SENSORS_PROC_REAL_READ) { smsc47m1_update_client(client); results[0] = PWM_FROM_REG(data->pwm[nr - 1]); - results[1] = data->pwm[nr - 1] >> 7; + results[1] = data->pwm[nr - 1] & 0x01; *nrels_mag = 2; } else if (operation == SENSORS_PROC_REAL_WRITE) { if (*nrels_mag >= 1) { - data->pwm[nr - 1] &= 0x80; + data->pwm[nr - 1] &= 0x81; data->pwm[nr - 1] |= PWM_TO_REG(results[0]); if (*nrels_mag >= 2) { - if(results[1] && (!(data->pwm[nr-1] & 0x80))) { - /* output PWM */ + if(results[1] && (!(data->pwm[nr-1] & 0x01))) { + /* enable PWM */ +/* hope BIOS did it already smsc47m1_write_value(client, SMSC47M1_REG_PPIN(nr), 0x04); - data->pwm[nr - 1] |= 0x80; +*/ + data->pwm[nr - 1] |= 0x01; + } else if((!results[1]) && (data->pwm[nr-1] & 0x01)) { + /* disable PWM */ + data->pwm[nr - 1] &= 0xfe; } } smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), - data->pwm[nr - 1]); + data->pwm[nr - 1]); } } }