Commit f7dda4d7 authored by Colin Leroy's avatar Colin Leroy Committed by Linus Torvalds

[PATCH] clean up therm_adt746x

This patch cleans therm_adt746x a bit: lines at maximum 80 chars width,
dispatches the big function in three little ones.

Functionality not changed.
Signed-off-by: default avatarColin Leroy <colin@colino.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 36edbcab
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -51,16 +52,21 @@ static int limit_adjust = 0; ...@@ -51,16 +52,21 @@ static int limit_adjust = 0;
static int fan_speed = -1; static int fan_speed = -1;
MODULE_AUTHOR("Colin Leroy <colin@colino.net>"); MODULE_AUTHOR("Colin Leroy <colin@colino.net>");
MODULE_DESCRIPTION("Driver for ADT746x thermostat in iBook G4 and Powerbook G4 Alu"); MODULE_DESCRIPTION("Driver for ADT746x thermostat in iBook G4 and "
"Powerbook G4 Alu");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_PARM(limit_adjust,"i"); MODULE_PARM(limit_adjust,"i");
MODULE_PARM_DESC(limit_adjust,"Adjust maximum temperatures (50 cpu, 70 gpu) by N degrees."); MODULE_PARM_DESC(limit_adjust,"Adjust maximum temperatures (50 cpu, 70 gpu) "
"by N degrees.");
MODULE_PARM(fan_speed,"i"); MODULE_PARM(fan_speed,"i");
MODULE_PARM_DESC(fan_speed,"Specify fan speed (0-255) when lim < temp < lim+8 (default 128)"); MODULE_PARM_DESC(fan_speed,"Specify fan speed (0-255) when lim < temp < lim+8 "
"(default 128)");
struct thermostat { struct thermostat {
struct i2c_client clt; struct i2c_client clt;
u8 temps[3];
u8 cached_temp[3]; u8 cached_temp[3];
u8 initial_limits[3]; u8 initial_limits[3];
u8 limits[3]; u8 limits[3];
...@@ -74,7 +80,9 @@ static struct of_device * of_dev; ...@@ -74,7 +80,9 @@ static struct of_device * of_dev;
static struct thermostat* thermostat; static struct thermostat* thermostat;
static struct task_struct *thread_therm = NULL; static struct task_struct *thread_therm = NULL;
static int attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno); static int attach_one_thermostat(struct i2c_adapter *adapter, int addr,
int busno);
static void write_both_fan_speed(struct thermostat *th, int speed); static void write_both_fan_speed(struct thermostat *th, int speed);
static void write_fan_speed(struct thermostat *th, int speed, int fan); static void write_fan_speed(struct thermostat *th, int speed, int fan);
...@@ -140,10 +148,11 @@ detach_thermostat(struct i2c_adapter *adapter) ...@@ -140,10 +148,11 @@ detach_thermostat(struct i2c_adapter *adapter)
kthread_stop(thread_therm); kthread_stop(thread_therm);
} }
printk(KERN_INFO "adt746x: Putting max temperatures back from %d, %d, %d," printk(KERN_INFO "adt746x: Putting max temperatures back from "
" to %d, %d, %d\n", "%d, %d, %d to %d, %d, %d\n",
th->limits[0], th->limits[1], th->limits[2], th->limits[0], th->limits[1], th->limits[2],
th->initial_limits[0], th->initial_limits[1], th->initial_limits[2]); th->initial_limits[0], th->initial_limits[1],
th->initial_limits[2]);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
write_reg(th, LIMIT_REG[i], th->initial_limits[i]); write_reg(th, LIMIT_REG[i], th->initial_limits[i]);
...@@ -202,11 +211,11 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan) ...@@ -202,11 +211,11 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan)
if (th->last_speed[fan] != speed) { if (th->last_speed[fan] != speed) {
if (speed == -1) if (speed == -1)
printk(KERN_INFO "adt746x: Setting speed to: automatic for %s fan.\n", printk(KERN_INFO "adt746x: Setting speed to automatic "
fan?"GPU":"CPU"); "for %s fan.\n", fan?"GPU":"CPU");
else else
printk(KERN_INFO "adt746x: Setting speed to: %d for %s fan.\n", printk(KERN_INFO "adt746x: Setting speed to %d "
speed, fan?"GPU":"CPU"); "for %s fan.\n", speed, fan?"GPU":"CPU");
} else } else
return; return;
...@@ -217,8 +226,11 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan) ...@@ -217,8 +226,11 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan)
} else { } else {
/* back to automatic */ /* back to automatic */
if(therm_type == ADT7460) { if(therm_type == ADT7460) {
manual = read_reg(th, MANUAL_MODE[fan]) & (~MANUAL_MASK); manual = read_reg(th,
write_reg(th, MANUAL_MODE[fan], manual|REM_CONTROL[fan]); MANUAL_MODE[fan]) & (~MANUAL_MASK);
write_reg(th,
MANUAL_MODE[fan], manual|REM_CONTROL[fan]);
} else { } else {
manual = read_reg(th, MANUAL_MODE[fan]); manual = read_reg(th, MANUAL_MODE[fan]);
write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK)); write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK));
...@@ -228,52 +240,61 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan) ...@@ -228,52 +240,61 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan)
th->last_speed[fan] = speed; th->last_speed[fan] = speed;
} }
static int monitor_task(void *arg) static void read_sensors(struct thermostat *th)
{ {
struct thermostat* th = arg; int i = 0;
u8 temps[3];
u8 lims[3];
int i;
#ifdef DEBUG
int mfan_speed;
#endif
while(!kthread_should_stop()) {
if (current->flags & PF_FREEZE)
refrigerator(PF_FREEZE);
msleep_interruptible(2000); for (i = 0; i < 3; i++)
th->temps[i] = read_reg(th, TEMP_REG[i]);
}
/* Check status */ #ifdef DEBUG
/* local : chip */ static void display_stats(struct thermostat *th)
/* remote 1: CPU ?*/ {
/* remote 2: GPU ?*/ if (th->temps[0] != th->cached_temp[0]
#ifndef DEBUG || th->temps[1] != th->cached_temp[1]
if (fan_speed != -1) { || th->temps[2] != th->cached_temp[2]) {
#endif printk(KERN_INFO "adt746x: Temperature infos:"
for (i = 0; i < 3; i++) { " thermostats: %d,%d,%d;"
temps[i] = read_reg(th, TEMP_REG[i]); " limits: %d,%d,%d;"
lims[i] = th->limits[i]; " fan speed: %d RPM\n",
} th->temps[0], th->temps[1], th->temps[2],
#ifndef DEBUG th->limits[0], th->limits[1], th->limits[2],
read_fan_speed(th, FAN_SPEED[0]));
} }
th->cached_temp[0] = th->temps[0];
th->cached_temp[1] = th->temps[1];
th->cached_temp[2] = th->temps[2];
}
#endif #endif
if (fan_speed != -1) {
int lastvar = 0; /* for iBook */ static void update_fans_speed (struct thermostat *th)
for (i = 1; i < 3; i++) { /* we don't care about local sensor */ {
int lastvar = 0; /* last variation, for iBook */
int i = 0;
/* we don't care about local sensor, so we start at sensor 1 */
for (i = 1; i < 3; i++) {
int started = 0; int started = 0;
int fan_number = (therm_type == ADT7460 && i == 2); int fan_number = (therm_type == ADT7460 && i == 2);
int var = temps[i] - lims[i]; int var = th->temps[i] - th->limits[i];
if (var > 8) { if (var > 8) {
if (th->overriding[fan_number] == 0) if (th->overriding[fan_number] == 0)
printk(KERN_INFO "adt746x: Limit exceeded by %d, overriding specified fan speed for %s.\n", printk(KERN_INFO "adt746x: Limit exceeded by "
var, fan_number?"GPU":"CPU"); "%d, overriding specified fan speed "
"for %s.\n", var,
fan_number?"GPU":"CPU");
th->overriding[fan_number] = 1; th->overriding[fan_number] = 1;
write_fan_speed(th, 255, fan_number); write_fan_speed(th, 255, fan_number);
started = 1; started = 1;
} else if ((!th->overriding[fan_number] || var < 6) && var > 0) { } else if ((!th->overriding[fan_number] || var < 6) && var > 0) {
if (th->overriding[fan_number] == 1) if (th->overriding[fan_number] == 1)
printk(KERN_INFO "adt746x: Limit exceeded by %d, setting speed to specified for %s.\n", printk(KERN_INFO "adt746x: Limit exceeded by "
var, fan_number?"GPU":"CPU"); "%d, setting speed to specified "
"for %s.\n", var,
fan_number?"GPU":"CPU");
th->overriding[fan_number] = 0; th->overriding[fan_number] = 0;
write_fan_speed(th, fan_speed, fan_number); write_fan_speed(th, fan_speed, fan_number);
started = 1; started = 1;
...@@ -282,7 +303,8 @@ static int monitor_task(void *arg) ...@@ -282,7 +303,8 @@ static int monitor_task(void *arg)
* so cold (lastvar >= -1) */ * so cold (lastvar >= -1) */
if (therm_type == ADT7460 || lastvar < -1 || i == 1) { if (therm_type == ADT7460 || lastvar < -1 || i == 1) {
if (th->last_speed[fan_number] != 0) if (th->last_speed[fan_number] != 0)
printk(KERN_INFO "adt746x: Stopping %s fan.\n", printk(KERN_INFO "adt746x: Stopping %s "
"fan.\n",
fan_number?"GPU":"CPU"); fan_number?"GPU":"CPU");
write_fan_speed(th, 0, fan_number); write_fan_speed(th, 0, fan_number);
} }
...@@ -291,36 +313,41 @@ static int monitor_task(void *arg) ...@@ -291,36 +313,41 @@ static int monitor_task(void *arg)
lastvar = var; lastvar = var;
if (started && therm_type == ADT7467) if (started && therm_type == ADT7467)
break; /* we don't want to re-stop the fan return; /* we don't want to re-stop the fan
* if CPU is heating and GPU is not */ * if CPU is heating and GPU is not */
} }
} }
#ifdef DEBUG
mfan_speed = read_fan_speed(th, FAN_SPEED[0]);
/* only one fan in the iBook G4 */
if (temps[0] != th->cached_temp[0] static int monitor_task(void *arg)
|| temps[1] != th->cached_temp[1] {
|| temps[2] != th->cached_temp[2]) { struct thermostat* th = arg;
printk(KERN_INFO "adt746x: Temperature infos:"
" thermostats: %d,%d,%d;" while(!kthread_should_stop()) {
" limits: %d,%d,%d;" if (current->flags & PF_FREEZE)
" fan speed: %d RPM\n", refrigerator(PF_FREEZE);
temps[0], temps[1], temps[2],
lims[0], lims[1], lims[2], msleep_interruptible(2000);
mfan_speed);
} #ifndef DEBUG
th->cached_temp[0] = temps[0]; if (fan_speed != -1)
th->cached_temp[1] = temps[1]; read_sensors(th);
th->cached_temp[2] = temps[2]; #else
read_sensors(th);
#endif
if (fan_speed != -1)
update_fans_speed(th);
#ifdef DEBUG
display_stats(th);
#endif #endif
} }
return 0; return 0;
} }
static void static void set_limit(struct thermostat *th, int i)
set_limit(struct thermostat *th, int i)
{ {
/* Set CPU limit higher to avoid powerdowns */ /* Set CPU limit higher to avoid powerdowns */
th->limits[i] = default_limits_chip[i] + limit_adjust; th->limits[i] = default_limits_chip[i] + limit_adjust;
...@@ -330,8 +357,8 @@ set_limit(struct thermostat *th, int i) ...@@ -330,8 +357,8 @@ set_limit(struct thermostat *th, int i)
th->limits[i] = default_limits_local[i] + limit_adjust; th->limits[i] = default_limits_local[i] + limit_adjust;
} }
static int static int attach_one_thermostat(struct i2c_adapter *adapter, int addr,
attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno) int busno)
{ {
struct thermostat* th; struct thermostat* th;
int rc; int rc;
...@@ -339,9 +366,13 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno) ...@@ -339,9 +366,13 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno)
if (thermostat) if (thermostat)
return 0; return 0;
th = (struct thermostat *)kmalloc(sizeof(struct thermostat), GFP_KERNEL);
th = (struct thermostat *)
kmalloc(sizeof(struct thermostat), GFP_KERNEL);
if (!th) if (!th)
return -ENOMEM; return -ENOMEM;
memset(th, 0, sizeof(*th)); memset(th, 0, sizeof(*th));
th->clt.addr = addr; th->clt.addr = addr;
th->clt.adapter = adapter; th->clt.adapter = adapter;
...@@ -351,13 +382,14 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno) ...@@ -351,13 +382,14 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno)
rc = read_reg(th, 0); rc = read_reg(th, 0);
if (rc < 0) { if (rc < 0) {
printk(KERN_ERR "adt746x: Thermostat failed to read config from bus %d !\n", printk(KERN_ERR "adt746x: Thermostat failed to read config "
"from bus %d !\n",
busno); busno);
kfree(th); kfree(th);
return -ENODEV; return -ENODEV;
} }
/* force manual control to start the fan quieter */
/* force manual control to start the fan quieter */
if (fan_speed == -1) if (fan_speed == -1)
fan_speed=128; fan_speed=128;
...@@ -375,13 +407,15 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno) ...@@ -375,13 +407,15 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno)
printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d" printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d"
" to %d, %d, %d\n", " to %d, %d, %d\n",
th->initial_limits[0], th->initial_limits[1], th->initial_limits[2], th->initial_limits[0], th->initial_limits[1],
th->limits[0], th->limits[1], th->limits[2]); th->initial_limits[2], th->limits[0], th->limits[1],
th->limits[2]);
thermostat = th; thermostat = th;
if (i2c_attach_client(&th->clt)) { if (i2c_attach_client(&th->clt)) {
printk(KERN_INFO "adt746x: Thermostat failed to attach client !\n"); printk(KERN_INFO "adt746x: Thermostat failed to attach "
"client !\n");
thermostat = NULL; thermostat = NULL;
kfree(th); kfree(th);
return -ENODEV; return -ENODEV;
...@@ -392,8 +426,10 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno) ...@@ -392,8 +426,10 @@ attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno)
th->last_speed[1] = -2; th->last_speed[1] = -2;
if (fan_speed != -1) { if (fan_speed != -1) {
/* manual mode, stop fans */
write_both_fan_speed(th, 0); write_both_fan_speed(th, 0);
} else { } else {
/* automatic mode */
write_both_fan_speed(th, -1); write_both_fan_speed(th, -1);
} }
...@@ -510,7 +546,8 @@ thermostat_init(void) ...@@ -510,7 +546,8 @@ thermostat_init(void)
therm_bus = ((*prop) >> 8) & 0x0f; therm_bus = ((*prop) >> 8) & 0x0f;
therm_address = ((*prop) & 0xff) >> 1; therm_address = ((*prop) & 0xff) >> 1;
printk(KERN_INFO "adt746x: Thermostat bus: %d, address: 0x%02x, limit_adjust: %d, fan_speed: %d\n", printk(KERN_INFO "adt746x: Thermostat bus: %d, address: 0x%02x, "
"limit_adjust: %d, fan_speed: %d\n",
therm_bus, therm_address, limit_adjust, fan_speed); therm_bus, therm_address, limit_adjust, fan_speed);
of_dev = of_platform_device_create(np, "temperatures"); of_dev = of_platform_device_create(np, "temperatures");
...@@ -548,8 +585,11 @@ thermostat_exit(void) ...@@ -548,8 +585,11 @@ thermostat_exit(void)
device_remove_file(&of_dev->dev, &dev_attr_limit_adjust); device_remove_file(&of_dev->dev, &dev_attr_limit_adjust);
device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed); device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed);
device_remove_file(&of_dev->dev, &dev_attr_cpu_fan_speed); device_remove_file(&of_dev->dev, &dev_attr_cpu_fan_speed);
if(therm_type == ADT7460) if(therm_type == ADT7460)
device_remove_file(&of_dev->dev, &dev_attr_gpu_fan_speed); device_remove_file(&of_dev->dev,
&dev_attr_gpu_fan_speed);
of_device_unregister(of_dev); of_device_unregister(of_dev);
} }
i2c_del_driver(&thermostat_driver); i2c_del_driver(&thermostat_driver);
......
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