Commit ac171c46 authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Linus Torvalds

[PATCH] powerpc: Thermal control for dual core G5s

This patch adds a windfarm module, windfarm_pm112, for the dual core G5s
(both 2 and 4 core models), keeping the machine from getting into
vacuum-cleaner mode ;) For proper credits, the patch was initially
written by Paul Mackerras, and slightly reworked by me to add overtemp
handling among others. The patch also removes the sysfs attributes from
windfarm_pm81 and windfarm_pm91 and instead adds code to the windfarm
core to automagically expose attributes for sensor & controls.
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 746f956b
...@@ -187,6 +187,14 @@ config WINDFARM_PM91 ...@@ -187,6 +187,14 @@ config WINDFARM_PM91
This driver provides thermal control for the PowerMac9,1 This driver provides thermal control for the PowerMac9,1
which is the recent (SMU based) single CPU desktop G5 which is the recent (SMU based) single CPU desktop G5
config WINDFARM_PM112
tristate "Support for thermal management on PowerMac11,2"
depends on WINDFARM && I2C && PMAC_SMU
select I2C_PMAC_SMU
help
This driver provides thermal control for the PowerMac11,2
which are the recent dual and quad G5 machines using the
970MP dual-core processor.
config ANSLCD config ANSLCD
tristate "Support for ANS LCD display" tristate "Support for ANS LCD display"
......
...@@ -35,3 +35,8 @@ obj-$(CONFIG_WINDFARM_PM91) += windfarm_smu_controls.o \ ...@@ -35,3 +35,8 @@ obj-$(CONFIG_WINDFARM_PM91) += windfarm_smu_controls.o \
windfarm_smu_sensors.o \ windfarm_smu_sensors.o \
windfarm_lm75_sensor.o windfarm_pid.o \ windfarm_lm75_sensor.o windfarm_pid.o \
windfarm_cpufreq_clamp.o windfarm_pm91.o windfarm_cpufreq_clamp.o windfarm_pm91.o
obj-$(CONFIG_WINDFARM_PM112) += windfarm_pm112.o windfarm_smu_sat.o \
windfarm_smu_controls.o \
windfarm_smu_sensors.o \
windfarm_max6690_sensor.o \
windfarm_lm75_sensor.o windfarm_pid.o
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/device.h>
/* Display a 16.16 fixed point value */ /* Display a 16.16 fixed point value */
#define FIX32TOPRINT(f) ((f) >> 16),((((f) & 0xffff) * 1000) >> 16) #define FIX32TOPRINT(f) ((f) >> 16),((((f) & 0xffff) * 1000) >> 16)
...@@ -39,6 +40,7 @@ struct wf_control { ...@@ -39,6 +40,7 @@ struct wf_control {
char *name; char *name;
int type; int type;
struct kref ref; struct kref ref;
struct device_attribute attr;
}; };
#define WF_CONTROL_TYPE_GENERIC 0 #define WF_CONTROL_TYPE_GENERIC 0
...@@ -87,6 +89,7 @@ struct wf_sensor { ...@@ -87,6 +89,7 @@ struct wf_sensor {
struct wf_sensor_ops *ops; struct wf_sensor_ops *ops;
char *name; char *name;
struct kref ref; struct kref ref;
struct device_attribute attr;
}; };
/* Same lifetime rules as controls */ /* Same lifetime rules as controls */
......
...@@ -56,6 +56,10 @@ static unsigned int wf_overtemp; ...@@ -56,6 +56,10 @@ static unsigned int wf_overtemp;
static unsigned int wf_overtemp_counter; static unsigned int wf_overtemp_counter;
struct task_struct *wf_thread; struct task_struct *wf_thread;
static struct platform_device wf_platform_device = {
.name = "windfarm",
};
/* /*
* Utilities & tick thread * Utilities & tick thread
*/ */
...@@ -157,6 +161,40 @@ static void wf_control_release(struct kref *kref) ...@@ -157,6 +161,40 @@ static void wf_control_release(struct kref *kref)
kfree(ct); kfree(ct);
} }
static ssize_t wf_show_control(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wf_control *ctrl = container_of(attr, struct wf_control, attr);
s32 val = 0;
int err;
err = ctrl->ops->get_value(ctrl, &val);
if (err < 0)
return err;
return sprintf(buf, "%d\n", val);
}
/* This is really only for debugging... */
static ssize_t wf_store_control(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wf_control *ctrl = container_of(attr, struct wf_control, attr);
int val;
int err;
char *endp;
val = simple_strtoul(buf, &endp, 0);
while (endp < buf + count && (*endp == ' ' || *endp == '\n'))
++endp;
if (endp - buf < count)
return -EINVAL;
err = ctrl->ops->set_value(ctrl, val);
if (err < 0)
return err;
return count;
}
int wf_register_control(struct wf_control *new_ct) int wf_register_control(struct wf_control *new_ct)
{ {
struct wf_control *ct; struct wf_control *ct;
...@@ -173,6 +211,13 @@ int wf_register_control(struct wf_control *new_ct) ...@@ -173,6 +211,13 @@ int wf_register_control(struct wf_control *new_ct)
kref_init(&new_ct->ref); kref_init(&new_ct->ref);
list_add(&new_ct->link, &wf_controls); list_add(&new_ct->link, &wf_controls);
new_ct->attr.attr.name = new_ct->name;
new_ct->attr.attr.owner = THIS_MODULE;
new_ct->attr.attr.mode = 0644;
new_ct->attr.show = wf_show_control;
new_ct->attr.store = wf_store_control;
device_create_file(&wf_platform_device.dev, &new_ct->attr);
DBG("wf: Registered control %s\n", new_ct->name); DBG("wf: Registered control %s\n", new_ct->name);
wf_notify(WF_EVENT_NEW_CONTROL, new_ct); wf_notify(WF_EVENT_NEW_CONTROL, new_ct);
...@@ -247,6 +292,19 @@ static void wf_sensor_release(struct kref *kref) ...@@ -247,6 +292,19 @@ static void wf_sensor_release(struct kref *kref)
kfree(sr); kfree(sr);
} }
static ssize_t wf_show_sensor(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wf_sensor *sens = container_of(attr, struct wf_sensor, attr);
s32 val = 0;
int err;
err = sens->ops->get_value(sens, &val);
if (err < 0)
return err;
return sprintf(buf, "%d.%03d\n", FIX32TOPRINT(val));
}
int wf_register_sensor(struct wf_sensor *new_sr) int wf_register_sensor(struct wf_sensor *new_sr)
{ {
struct wf_sensor *sr; struct wf_sensor *sr;
...@@ -263,6 +321,13 @@ int wf_register_sensor(struct wf_sensor *new_sr) ...@@ -263,6 +321,13 @@ int wf_register_sensor(struct wf_sensor *new_sr)
kref_init(&new_sr->ref); kref_init(&new_sr->ref);
list_add(&new_sr->link, &wf_sensors); list_add(&new_sr->link, &wf_sensors);
new_sr->attr.attr.name = new_sr->name;
new_sr->attr.attr.owner = THIS_MODULE;
new_sr->attr.attr.mode = 0444;
new_sr->attr.show = wf_show_sensor;
new_sr->attr.store = NULL;
device_create_file(&wf_platform_device.dev, &new_sr->attr);
DBG("wf: Registered sensor %s\n", new_sr->name); DBG("wf: Registered sensor %s\n", new_sr->name);
wf_notify(WF_EVENT_NEW_SENSOR, new_sr); wf_notify(WF_EVENT_NEW_SENSOR, new_sr);
...@@ -396,10 +461,6 @@ int wf_is_overtemp(void) ...@@ -396,10 +461,6 @@ int wf_is_overtemp(void)
} }
EXPORT_SYMBOL_GPL(wf_is_overtemp); EXPORT_SYMBOL_GPL(wf_is_overtemp);
static struct platform_device wf_platform_device = {
.name = "windfarm",
};
static int __init windfarm_core_init(void) static int __init windfarm_core_init(void)
{ {
DBG("wf: core loaded\n"); DBG("wf: core loaded\n");
......
/*
* Windfarm PowerMac thermal control. MAX6690 sensor.
*
* Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
*
* Use and redistribute under the terms of the GNU GPL v2.
*/
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <asm/prom.h>
#include <asm/pmac_low_i2c.h>
#include "windfarm.h"
#define VERSION "0.1"
/* This currently only exports the external temperature sensor,
since that's all the control loops need. */
/* Some MAX6690 register numbers */
#define MAX6690_INTERNAL_TEMP 0
#define MAX6690_EXTERNAL_TEMP 1
struct wf_6690_sensor {
struct i2c_client i2c;
struct wf_sensor sens;
};
#define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
#define i2c_to_6690(x) container_of((x), struct wf_6690_sensor, i2c)
static int wf_max6690_attach(struct i2c_adapter *adapter);
static int wf_max6690_detach(struct i2c_client *client);
static struct i2c_driver wf_max6690_driver = {
.driver = {
.name = "wf_max6690",
},
.attach_adapter = wf_max6690_attach,
.detach_client = wf_max6690_detach,
};
static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
{
struct wf_6690_sensor *max = wf_to_6690(sr);
s32 data;
if (max->i2c.adapter == NULL)
return -ENODEV;
/* chip gets initialized by firmware */
data = i2c_smbus_read_byte_data(&max->i2c, MAX6690_EXTERNAL_TEMP);
if (data < 0)
return data;
*value = data << 16;
return 0;
}
static void wf_max6690_release(struct wf_sensor *sr)
{
struct wf_6690_sensor *max = wf_to_6690(sr);
if (max->i2c.adapter) {
i2c_detach_client(&max->i2c);
max->i2c.adapter = NULL;
}
kfree(max);
}
static struct wf_sensor_ops wf_max6690_ops = {
.get_value = wf_max6690_get,
.release = wf_max6690_release,
.owner = THIS_MODULE,
};
static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr)
{
struct wf_6690_sensor *max;
char *name = "u4-temp";
max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
if (max == NULL) {
printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor %s: "
"no memory\n", name);
return;
}
max->sens.ops = &wf_max6690_ops;
max->sens.name = name;
max->i2c.addr = addr >> 1;
max->i2c.adapter = adapter;
max->i2c.driver = &wf_max6690_driver;
strncpy(max->i2c.name, name, I2C_NAME_SIZE-1);
if (i2c_attach_client(&max->i2c)) {
printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor\n");
goto fail;
}
if (wf_register_sensor(&max->sens)) {
i2c_detach_client(&max->i2c);
goto fail;
}
return;
fail:
kfree(max);
}
static int wf_max6690_attach(struct i2c_adapter *adapter)
{
struct device_node *busnode, *dev = NULL;
struct pmac_i2c_bus *bus;
const char *loc;
u32 *reg;
bus = pmac_i2c_adapter_to_bus(adapter);
if (bus == NULL)
return -ENODEV;
busnode = pmac_i2c_get_bus_node(bus);
while ((dev = of_get_next_child(busnode, dev)) != NULL) {
if (!device_is_compatible(dev, "max6690"))
continue;
loc = get_property(dev, "hwsensor-location", NULL);
reg = (u32 *) get_property(dev, "reg", NULL);
if (!loc || !reg)
continue;
printk("found max6690, loc=%s reg=%x\n", loc, *reg);
if (strcmp(loc, "BACKSIDE"))
continue;
wf_max6690_create(adapter, *reg);
}
return 0;
}
static int wf_max6690_detach(struct i2c_client *client)
{
struct wf_6690_sensor *max = i2c_to_6690(client);
max->i2c.adapter = NULL;
wf_unregister_sensor(&max->sens);
return 0;
}
static int __init wf_max6690_sensor_init(void)
{
return i2c_add_driver(&wf_max6690_driver);
}
static void __exit wf_max6690_sensor_exit(void)
{
i2c_del_driver(&wf_max6690_driver);
}
module_init(wf_max6690_sensor_init);
module_exit(wf_max6690_sensor_exit);
MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
MODULE_LICENSE("GPL");
...@@ -88,8 +88,8 @@ EXPORT_SYMBOL_GPL(wf_cpu_pid_init); ...@@ -88,8 +88,8 @@ EXPORT_SYMBOL_GPL(wf_cpu_pid_init);
s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp) s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp)
{ {
s64 error, integ, deriv, prop; s64 integ, deriv, prop;
s32 target, sval, adj; s32 error, target, sval, adj;
int i, hlen = st->param.history_len; int i, hlen = st->param.history_len;
/* Calculate error term */ /* Calculate error term */
...@@ -117,7 +117,7 @@ s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp) ...@@ -117,7 +117,7 @@ s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp)
integ += st->errors[(st->index + hlen - i) % hlen]; integ += st->errors[(st->index + hlen - i) % hlen];
integ *= st->param.interval; integ *= st->param.interval;
integ *= st->param.gr; integ *= st->param.gr;
sval = st->param.tmax - ((integ >> 20) & 0xffffffff); sval = st->param.tmax - (s32)(integ >> 20);
adj = min(st->param.ttarget, sval); adj = min(st->param.ttarget, sval);
DBG("integ: %lx, sval: %lx, adj: %lx\n", integ, sval, adj); DBG("integ: %lx, sval: %lx, adj: %lx\n", integ, sval, adj);
...@@ -129,7 +129,7 @@ s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp) ...@@ -129,7 +129,7 @@ s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp)
deriv *= st->param.gd; deriv *= st->param.gd;
/* Calculate proportional term */ /* Calculate proportional term */
prop = (new_temp - adj); prop = st->last_delta = (new_temp - adj);
prop *= st->param.gp; prop *= st->param.gp;
DBG("deriv: %lx, prop: %lx\n", deriv, prop); DBG("deriv: %lx, prop: %lx\n", deriv, prop);
......
...@@ -72,6 +72,7 @@ struct wf_cpu_pid_state { ...@@ -72,6 +72,7 @@ struct wf_cpu_pid_state {
int index; /* index of current power */ int index; /* index of current power */
int tindex; /* index of current temp */ int tindex; /* index of current temp */
s32 target; /* current target value */ s32 target; /* current target value */
s32 last_delta; /* last Tactual - Ttarget */
s32 powers[WF_PID_MAX_HISTORY]; /* power history buffer */ s32 powers[WF_PID_MAX_HISTORY]; /* power history buffer */
s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */ s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */
s32 temps[2]; /* temp. history buffer */ s32 temps[2]; /* temp. history buffer */
......
This diff is collapsed.
...@@ -538,45 +538,6 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st) ...@@ -538,45 +538,6 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
} }
} }
/*
* ****** Attributes ******
*
*/
#define BUILD_SHOW_FUNC_FIX(name, data) \
static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
ssize_t r; \
s32 val = 0; \
data->ops->get_value(data, &val); \
r = sprintf(buf, "%d.%03d", FIX32TOPRINT(val)); \
return r; \
} \
static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
#define BUILD_SHOW_FUNC_INT(name, data) \
static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
s32 val = 0; \
data->ops->get_value(data, &val); \
return sprintf(buf, "%d", val); \
} \
static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
BUILD_SHOW_FUNC_INT(cpu_fan, fan_cpu_main);
BUILD_SHOW_FUNC_INT(sys_fan, fan_system);
BUILD_SHOW_FUNC_INT(hd_fan, fan_hd);
BUILD_SHOW_FUNC_FIX(cpu_temp, sensor_cpu_temp);
BUILD_SHOW_FUNC_FIX(cpu_power, sensor_cpu_power);
BUILD_SHOW_FUNC_FIX(hd_temp, sensor_hd_temp);
/* /*
* ****** Setup / Init / Misc ... ****** * ****** Setup / Init / Misc ... ******
* *
...@@ -654,17 +615,13 @@ static void wf_smu_new_control(struct wf_control *ct) ...@@ -654,17 +615,13 @@ static void wf_smu_new_control(struct wf_control *ct)
return; return;
if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-fan")) { if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-fan")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_cpu_main = ct; fan_cpu_main = ct;
device_create_file(wf_smu_dev, &dev_attr_cpu_fan);
}
} }
if (fan_system == NULL && !strcmp(ct->name, "system-fan")) { if (fan_system == NULL && !strcmp(ct->name, "system-fan")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_system = ct; fan_system = ct;
device_create_file(wf_smu_dev, &dev_attr_sys_fan);
}
} }
if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) { if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) {
...@@ -683,10 +640,8 @@ static void wf_smu_new_control(struct wf_control *ct) ...@@ -683,10 +640,8 @@ static void wf_smu_new_control(struct wf_control *ct)
} }
if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) { if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_hd = ct; fan_hd = ct;
device_create_file(wf_smu_dev, &dev_attr_hd_fan);
}
} }
if (fan_system && fan_hd && fan_cpu_main && cpufreq_clamp) if (fan_system && fan_hd && fan_cpu_main && cpufreq_clamp)
...@@ -699,24 +654,18 @@ static void wf_smu_new_sensor(struct wf_sensor *sr) ...@@ -699,24 +654,18 @@ static void wf_smu_new_sensor(struct wf_sensor *sr)
return; return;
if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) { if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_cpu_power = sr; sensor_cpu_power = sr;
device_create_file(wf_smu_dev, &dev_attr_cpu_power);
}
} }
if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) { if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_cpu_temp = sr; sensor_cpu_temp = sr;
device_create_file(wf_smu_dev, &dev_attr_cpu_temp);
}
} }
if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) { if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_hd_temp = sr; sensor_hd_temp = sr;
device_create_file(wf_smu_dev, &dev_attr_hd_temp);
}
} }
if (sensor_cpu_power && sensor_cpu_temp && sensor_hd_temp) if (sensor_cpu_power && sensor_cpu_temp && sensor_hd_temp)
...@@ -794,32 +743,20 @@ static int wf_smu_remove(struct device *ddev) ...@@ -794,32 +743,20 @@ static int wf_smu_remove(struct device *ddev)
* with that except by adding locks all over... I'll do that * with that except by adding locks all over... I'll do that
* eventually but heh, who ever rmmod this module anyway ? * eventually but heh, who ever rmmod this module anyway ?
*/ */
if (sensor_cpu_power) { if (sensor_cpu_power)
device_remove_file(wf_smu_dev, &dev_attr_cpu_power);
wf_put_sensor(sensor_cpu_power); wf_put_sensor(sensor_cpu_power);
} if (sensor_cpu_temp)
if (sensor_cpu_temp) {
device_remove_file(wf_smu_dev, &dev_attr_cpu_temp);
wf_put_sensor(sensor_cpu_temp); wf_put_sensor(sensor_cpu_temp);
} if (sensor_hd_temp)
if (sensor_hd_temp) {
device_remove_file(wf_smu_dev, &dev_attr_hd_temp);
wf_put_sensor(sensor_hd_temp); wf_put_sensor(sensor_hd_temp);
}
/* Release all controls */ /* Release all controls */
if (fan_cpu_main) { if (fan_cpu_main)
device_remove_file(wf_smu_dev, &dev_attr_cpu_fan);
wf_put_control(fan_cpu_main); wf_put_control(fan_cpu_main);
} if (fan_hd)
if (fan_hd) {
device_remove_file(wf_smu_dev, &dev_attr_hd_fan);
wf_put_control(fan_hd); wf_put_control(fan_hd);
} if (fan_system)
if (fan_system) {
device_remove_file(wf_smu_dev, &dev_attr_sys_fan);
wf_put_control(fan_system); wf_put_control(fan_system);
}
if (cpufreq_clamp) if (cpufreq_clamp)
wf_put_control(cpufreq_clamp); wf_put_control(cpufreq_clamp);
......
...@@ -457,45 +457,6 @@ static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st) ...@@ -457,45 +457,6 @@ static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
} }
/*
* ****** Attributes ******
*
*/
#define BUILD_SHOW_FUNC_FIX(name, data) \
static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
ssize_t r; \
s32 val = 0; \
data->ops->get_value(data, &val); \
r = sprintf(buf, "%d.%03d", FIX32TOPRINT(val)); \
return r; \
} \
static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
#define BUILD_SHOW_FUNC_INT(name, data) \
static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
s32 val = 0; \
data->ops->get_value(data, &val); \
return sprintf(buf, "%d", val); \
} \
static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
BUILD_SHOW_FUNC_INT(cpu_fan, fan_cpu_main);
BUILD_SHOW_FUNC_INT(hd_fan, fan_hd);
BUILD_SHOW_FUNC_INT(slots_fan, fan_slots);
BUILD_SHOW_FUNC_FIX(cpu_temp, sensor_cpu_temp);
BUILD_SHOW_FUNC_FIX(cpu_power, sensor_cpu_power);
BUILD_SHOW_FUNC_FIX(hd_temp, sensor_hd_temp);
BUILD_SHOW_FUNC_FIX(slots_power, sensor_slots_power);
/* /*
* ****** Setup / Init / Misc ... ****** * ****** Setup / Init / Misc ... ******
* *
...@@ -581,10 +542,8 @@ static void wf_smu_new_control(struct wf_control *ct) ...@@ -581,10 +542,8 @@ static void wf_smu_new_control(struct wf_control *ct)
return; return;
if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) { if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_cpu_main = ct; fan_cpu_main = ct;
device_create_file(wf_smu_dev, &dev_attr_cpu_fan);
}
} }
if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) { if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) {
...@@ -603,17 +562,13 @@ static void wf_smu_new_control(struct wf_control *ct) ...@@ -603,17 +562,13 @@ static void wf_smu_new_control(struct wf_control *ct)
} }
if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) { if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_hd = ct; fan_hd = ct;
device_create_file(wf_smu_dev, &dev_attr_hd_fan);
}
} }
if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) { if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) {
if (wf_get_control(ct) == 0) { if (wf_get_control(ct) == 0)
fan_slots = ct; fan_slots = ct;
device_create_file(wf_smu_dev, &dev_attr_slots_fan);
}
} }
if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd && if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd &&
...@@ -627,31 +582,23 @@ static void wf_smu_new_sensor(struct wf_sensor *sr) ...@@ -627,31 +582,23 @@ static void wf_smu_new_sensor(struct wf_sensor *sr)
return; return;
if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) { if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_cpu_power = sr; sensor_cpu_power = sr;
device_create_file(wf_smu_dev, &dev_attr_cpu_power);
}
} }
if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) { if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_cpu_temp = sr; sensor_cpu_temp = sr;
device_create_file(wf_smu_dev, &dev_attr_cpu_temp);
}
} }
if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) { if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_hd_temp = sr; sensor_hd_temp = sr;
device_create_file(wf_smu_dev, &dev_attr_hd_temp);
}
} }
if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) { if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) {
if (wf_get_sensor(sr) == 0) { if (wf_get_sensor(sr) == 0)
sensor_slots_power = sr; sensor_slots_power = sr;
device_create_file(wf_smu_dev, &dev_attr_slots_power);
}
} }
if (sensor_cpu_power && sensor_cpu_temp && if (sensor_cpu_power && sensor_cpu_temp &&
...@@ -720,40 +667,26 @@ static int wf_smu_remove(struct device *ddev) ...@@ -720,40 +667,26 @@ static int wf_smu_remove(struct device *ddev)
* with that except by adding locks all over... I'll do that * with that except by adding locks all over... I'll do that
* eventually but heh, who ever rmmod this module anyway ? * eventually but heh, who ever rmmod this module anyway ?
*/ */
if (sensor_cpu_power) { if (sensor_cpu_power)
device_remove_file(wf_smu_dev, &dev_attr_cpu_power);
wf_put_sensor(sensor_cpu_power); wf_put_sensor(sensor_cpu_power);
} if (sensor_cpu_temp)
if (sensor_cpu_temp) {
device_remove_file(wf_smu_dev, &dev_attr_cpu_temp);
wf_put_sensor(sensor_cpu_temp); wf_put_sensor(sensor_cpu_temp);
} if (sensor_hd_temp)
if (sensor_hd_temp) {
device_remove_file(wf_smu_dev, &dev_attr_hd_temp);
wf_put_sensor(sensor_hd_temp); wf_put_sensor(sensor_hd_temp);
} if (sensor_slots_power)
if (sensor_slots_power) {
device_remove_file(wf_smu_dev, &dev_attr_slots_power);
wf_put_sensor(sensor_slots_power); wf_put_sensor(sensor_slots_power);
}
/* Release all controls */ /* Release all controls */
if (fan_cpu_main) { if (fan_cpu_main)
device_remove_file(wf_smu_dev, &dev_attr_cpu_fan);
wf_put_control(fan_cpu_main); wf_put_control(fan_cpu_main);
}
if (fan_cpu_second) if (fan_cpu_second)
wf_put_control(fan_cpu_second); wf_put_control(fan_cpu_second);
if (fan_cpu_third) if (fan_cpu_third)
wf_put_control(fan_cpu_third); wf_put_control(fan_cpu_third);
if (fan_hd) { if (fan_hd)
device_remove_file(wf_smu_dev, &dev_attr_hd_fan);
wf_put_control(fan_hd); wf_put_control(fan_hd);
} if (fan_slots)
if (fan_slots) {
device_remove_file(wf_smu_dev, &dev_attr_slots_fan);
wf_put_control(fan_slots); wf_put_control(fan_slots);
}
if (cpufreq_clamp) if (cpufreq_clamp)
wf_put_control(cpufreq_clamp); wf_put_control(cpufreq_clamp);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "windfarm.h" #include "windfarm.h"
#define VERSION "0.3" #define VERSION "0.4"
#undef DEBUG #undef DEBUG
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#define DBG(args...) do { } while(0) #define DBG(args...) do { } while(0)
#endif #endif
static int smu_supports_new_fans_ops = 1;
/* /*
* SMU fans control object * SMU fans control object
*/ */
...@@ -59,23 +61,49 @@ static int smu_set_fan(int pwm, u8 id, u16 value) ...@@ -59,23 +61,49 @@ static int smu_set_fan(int pwm, u8 id, u16 value)
/* Fill SMU command structure */ /* Fill SMU command structure */
cmd.cmd = SMU_CMD_FAN_COMMAND; cmd.cmd = SMU_CMD_FAN_COMMAND;
cmd.data_len = 14;
cmd.reply_len = 16;
cmd.data_buf = cmd.reply_buf = buffer;
cmd.status = 0;
cmd.done = smu_done_complete;
cmd.misc = &comp;
/* The SMU has an "old" and a "new" way of setting the fan speed
* Unfortunately, I found no reliable way to know which one works
* on a given machine model. After some investigations it appears
* that MacOS X just tries the new one, and if it fails fallbacks
* to the old ones ... Ugh.
*/
retry:
if (smu_supports_new_fans_ops) {
buffer[0] = 0x30;
buffer[1] = id;
*((u16 *)(&buffer[2])) = value;
cmd.data_len = 4;
} else {
if (id > 7)
return -EINVAL;
/* Fill argument buffer */ /* Fill argument buffer */
memset(buffer, 0, 16); memset(buffer, 0, 16);
buffer[0] = pwm ? 0x10 : 0x00; buffer[0] = pwm ? 0x10 : 0x00;
buffer[1] = 0x01 << id; buffer[1] = 0x01 << id;
*((u16 *)&buffer[2 + id * 2]) = value; *((u16 *)&buffer[2 + id * 2]) = value;
cmd.data_len = 14;
}
cmd.reply_len = 16;
cmd.data_buf = cmd.reply_buf = buffer;
cmd.status = 0;
cmd.done = smu_done_complete;
cmd.misc = &comp;
rc = smu_queue_cmd(&cmd); rc = smu_queue_cmd(&cmd);
if (rc) if (rc)
return rc; return rc;
wait_for_completion(&comp); wait_for_completion(&comp);
/* Handle fallback (see coment above) */
if (cmd.status != 0 && smu_supports_new_fans_ops) {
printk(KERN_WARNING "windfarm: SMU failed new fan command "
"falling back to old method\n");
smu_supports_new_fans_ops = 0;
goto retry;
}
return cmd.status; return cmd.status;
} }
...@@ -158,19 +186,29 @@ static struct smu_fan_control *smu_fan_create(struct device_node *node, ...@@ -158,19 +186,29 @@ static struct smu_fan_control *smu_fan_create(struct device_node *node,
/* Names used on desktop models */ /* Names used on desktop models */
if (!strcmp(l, "Rear Fan 0") || !strcmp(l, "Rear Fan") || if (!strcmp(l, "Rear Fan 0") || !strcmp(l, "Rear Fan") ||
!strcmp(l, "Rear fan 0") || !strcmp(l, "Rear fan")) !strcmp(l, "Rear fan 0") || !strcmp(l, "Rear fan") ||
!strcmp(l, "CPU A EXHAUST"))
fct->ctrl.name = "cpu-rear-fan-0"; fct->ctrl.name = "cpu-rear-fan-0";
else if (!strcmp(l, "Rear Fan 1") || !strcmp(l, "Rear fan 1")) else if (!strcmp(l, "Rear Fan 1") || !strcmp(l, "Rear fan 1") ||
!strcmp(l, "CPU B EXHAUST"))
fct->ctrl.name = "cpu-rear-fan-1"; fct->ctrl.name = "cpu-rear-fan-1";
else if (!strcmp(l, "Front Fan 0") || !strcmp(l, "Front Fan") || else if (!strcmp(l, "Front Fan 0") || !strcmp(l, "Front Fan") ||
!strcmp(l, "Front fan 0") || !strcmp(l, "Front fan")) !strcmp(l, "Front fan 0") || !strcmp(l, "Front fan") ||
!strcmp(l, "CPU A INTAKE"))
fct->ctrl.name = "cpu-front-fan-0"; fct->ctrl.name = "cpu-front-fan-0";
else if (!strcmp(l, "Front Fan 1") || !strcmp(l, "Front fan 1")) else if (!strcmp(l, "Front Fan 1") || !strcmp(l, "Front fan 1") ||
!strcmp(l, "CPU B INTAKE"))
fct->ctrl.name = "cpu-front-fan-1"; fct->ctrl.name = "cpu-front-fan-1";
else if (!strcmp(l, "Slots Fan") || !strcmp(l, "Slots fan")) else if (!strcmp(l, "CPU A PUMP"))
fct->ctrl.name = "cpu-pump-0";
else if (!strcmp(l, "Slots Fan") || !strcmp(l, "Slots fan") ||
!strcmp(l, "EXPANSION SLOTS INTAKE"))
fct->ctrl.name = "slots-fan"; fct->ctrl.name = "slots-fan";
else if (!strcmp(l, "Drive Bay") || !strcmp(l, "Drive bay")) else if (!strcmp(l, "Drive Bay") || !strcmp(l, "Drive bay") ||
!strcmp(l, "DRIVE BAY A INTAKE"))
fct->ctrl.name = "drive-bay-fan"; fct->ctrl.name = "drive-bay-fan";
else if (!strcmp(l, "BACKSIDE"))
fct->ctrl.name = "backside-fan";
/* Names used on iMac models */ /* Names used on iMac models */
if (!strcmp(l, "System Fan") || !strcmp(l, "System fan")) if (!strcmp(l, "System Fan") || !strcmp(l, "System fan"))
...@@ -223,7 +261,8 @@ static int __init smu_controls_init(void) ...@@ -223,7 +261,8 @@ static int __init smu_controls_init(void)
/* Look for RPM fans */ /* Look for RPM fans */
for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;) for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;)
if (!strcmp(fans->name, "rpm-fans")) if (!strcmp(fans->name, "rpm-fans") ||
device_is_compatible(fans, "smu-rpm-fans"))
break; break;
for (fan = NULL; for (fan = NULL;
fans && (fan = of_get_next_child(fans, fan)) != NULL;) { fans && (fan = of_get_next_child(fans, fan)) != NULL;) {
......
/*
* Windfarm PowerMac thermal control. SMU "satellite" controller sensors.
*
* Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
*
* Released under the terms of the GNU GPL v2.
*/
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/wait.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <asm/semaphore.h>
#include <asm/prom.h>
#include <asm/smu.h>
#include <asm/pmac_low_i2c.h>
#include "windfarm.h"
#define VERSION "0.2"
#define DEBUG
#ifdef DEBUG
#define DBG(args...) printk(args)
#else
#define DBG(args...) do { } while(0)
#endif
/* If the cache is older than 800ms we'll refetch it */
#define MAX_AGE msecs_to_jiffies(800)
struct wf_sat {
int nr;
atomic_t refcnt;
struct semaphore mutex;
unsigned long last_read; /* jiffies when cache last updated */
u8 cache[16];
struct i2c_client i2c;
struct device_node *node;
};
static struct wf_sat *sats[2];
struct wf_sat_sensor {
int index;
int index2; /* used for power sensors */
int shift;
struct wf_sat *sat;
struct wf_sensor sens;
};
#define wf_to_sat(c) container_of(c, struct wf_sat_sensor, sens)
#define i2c_to_sat(c) container_of(c, struct wf_sat, i2c)
static int wf_sat_attach(struct i2c_adapter *adapter);
static int wf_sat_detach(struct i2c_client *client);
static struct i2c_driver wf_sat_driver = {
.driver = {
.name = "wf_smu_sat",
},
.attach_adapter = wf_sat_attach,
.detach_client = wf_sat_detach,
};
/*
* XXX i2c_smbus_read_i2c_block_data doesn't pass the requested
* length down to the low-level driver, so we use this, which
* works well enough with the SMU i2c driver code...
*/
static int sat_read_block(struct i2c_client *client, u8 command,
u8 *values, int len)
{
union i2c_smbus_data data;
int err;
data.block[0] = len;
err = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA,
&data);
if (!err)
memcpy(values, data.block, len);
return err;
}
struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
unsigned int *size)
{
struct wf_sat *sat;
int err;
unsigned int i, len;
u8 *buf;
u8 data[4];
/* TODO: Add the resulting partition to the device-tree */
if (sat_id > 1 || (sat = sats[sat_id]) == NULL)
return NULL;
err = i2c_smbus_write_word_data(&sat->i2c, 8, id << 8);
if (err) {
printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err);
return NULL;
}
len = i2c_smbus_read_word_data(&sat->i2c, 9);
if (len < 0) {
printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n");
return NULL;
}
if (len == 0) {
printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id);
return NULL;
}
len = le16_to_cpu(len);
len = (len + 3) & ~3;
buf = kmalloc(len, GFP_KERNEL);
if (buf == NULL)
return NULL;
for (i = 0; i < len; i += 4) {
err = sat_read_block(&sat->i2c, 0xa, data, 4);
if (err) {
printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n",
err);
goto fail;
}
buf[i] = data[1];
buf[i+1] = data[0];
buf[i+2] = data[3];
buf[i+3] = data[2];
}
#ifdef DEBUG
DBG(KERN_DEBUG "sat %d partition %x:", sat_id, id);
for (i = 0; i < len; ++i)
DBG(" %x", buf[i]);
DBG("\n");
#endif
if (size)
*size = len;
return (struct smu_sdbp_header *) buf;
fail:
kfree(buf);
return NULL;
}
/* refresh the cache */
static int wf_sat_read_cache(struct wf_sat *sat)
{
int err;
err = sat_read_block(&sat->i2c, 0x3f, sat->cache, 16);
if (err)
return err;
sat->last_read = jiffies;
#ifdef LOTSA_DEBUG
{
int i;
DBG(KERN_DEBUG "wf_sat_get: data is");
for (i = 0; i < 16; ++i)
DBG(" %.2x", sat->cache[i]);
DBG("\n");
}
#endif
return 0;
}
static int wf_sat_get(struct wf_sensor *sr, s32 *value)
{
struct wf_sat_sensor *sens = wf_to_sat(sr);
struct wf_sat *sat = sens->sat;
int i, err;
s32 val;
if (sat->i2c.adapter == NULL)
return -ENODEV;
down(&sat->mutex);
if (time_after(jiffies, (sat->last_read + MAX_AGE))) {
err = wf_sat_read_cache(sat);
if (err)
goto fail;
}
i = sens->index * 2;
val = ((sat->cache[i] << 8) + sat->cache[i+1]) << sens->shift;
if (sens->index2 >= 0) {
i = sens->index2 * 2;
/* 4.12 * 8.8 -> 12.20; shift right 4 to get 16.16 */
val = (val * ((sat->cache[i] << 8) + sat->cache[i+1])) >> 4;
}
*value = val;
err = 0;
fail:
up(&sat->mutex);
return err;
}
static void wf_sat_release(struct wf_sensor *sr)
{
struct wf_sat_sensor *sens = wf_to_sat(sr);
struct wf_sat *sat = sens->sat;
if (atomic_dec_and_test(&sat->refcnt)) {
if (sat->i2c.adapter) {
i2c_detach_client(&sat->i2c);
sat->i2c.adapter = NULL;
}
if (sat->nr >= 0)
sats[sat->nr] = NULL;
kfree(sat);
}
kfree(sens);
}
static struct wf_sensor_ops wf_sat_ops = {
.get_value = wf_sat_get,
.release = wf_sat_release,
.owner = THIS_MODULE,
};
static void wf_sat_create(struct i2c_adapter *adapter, struct device_node *dev)
{
struct wf_sat *sat;
struct wf_sat_sensor *sens;
u32 *reg;
char *loc, *type;
u8 addr, chip, core;
struct device_node *child;
int shift, cpu, index;
char *name;
int vsens[2], isens[2];
reg = (u32 *) get_property(dev, "reg", NULL);
if (reg == NULL)
return;
addr = *reg;
DBG(KERN_DEBUG "wf_sat: creating sat at address %x\n", addr);
sat = kzalloc(sizeof(struct wf_sat), GFP_KERNEL);
if (sat == NULL)
return;
sat->nr = -1;
sat->node = of_node_get(dev);
atomic_set(&sat->refcnt, 0);
init_MUTEX(&sat->mutex);
sat->i2c.addr = (addr >> 1) & 0x7f;
sat->i2c.adapter = adapter;
sat->i2c.driver = &wf_sat_driver;
strncpy(sat->i2c.name, "smu-sat", I2C_NAME_SIZE-1);
if (i2c_attach_client(&sat->i2c)) {
printk(KERN_ERR "windfarm: failed to attach smu-sat to i2c\n");
goto fail;
}
vsens[0] = vsens[1] = -1;
isens[0] = isens[1] = -1;
child = NULL;
while ((child = of_get_next_child(dev, child)) != NULL) {
reg = (u32 *) get_property(child, "reg", NULL);
type = get_property(child, "device_type", NULL);
loc = get_property(child, "location", NULL);
if (reg == NULL || loc == NULL)
continue;
/* the cooked sensors are between 0x30 and 0x37 */
if (*reg < 0x30 || *reg > 0x37)
continue;
index = *reg - 0x30;
/* expect location to be CPU [AB][01] ... */
if (strncmp(loc, "CPU ", 4) != 0)
continue;
chip = loc[4] - 'A';
core = loc[5] - '0';
if (chip > 1 || core > 1) {
printk(KERN_ERR "wf_sat_create: don't understand "
"location %s for %s\n", loc, child->full_name);
continue;
}
cpu = 2 * chip + core;
if (sat->nr < 0)
sat->nr = chip;
else if (sat->nr != chip) {
printk(KERN_ERR "wf_sat_create: can't cope with "
"multiple CPU chips on one SAT (%s)\n", loc);
continue;
}
if (strcmp(type, "voltage-sensor") == 0) {
name = "cpu-voltage";
shift = 4;
vsens[core] = index;
} else if (strcmp(type, "current-sensor") == 0) {
name = "cpu-current";
shift = 8;
isens[core] = index;
} else if (strcmp(type, "temp-sensor") == 0) {
name = "cpu-temp";
shift = 10;
} else
continue; /* hmmm shouldn't happen */
/* the +16 is enough for "cpu-voltage-n" */
sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
if (sens == NULL) {
printk(KERN_ERR "wf_sat_create: couldn't create "
"%s sensor %d (no memory)\n", name, cpu);
continue;
}
sens->index = index;
sens->index2 = -1;
sens->shift = shift;
sens->sat = sat;
atomic_inc(&sat->refcnt);
sens->sens.ops = &wf_sat_ops;
sens->sens.name = (char *) (sens + 1);
snprintf(sens->sens.name, 16, "%s-%d", name, cpu);
if (wf_register_sensor(&sens->sens)) {
atomic_dec(&sat->refcnt);
kfree(sens);
}
}
/* make the power sensors */
for (core = 0; core < 2; ++core) {
if (vsens[core] < 0 || isens[core] < 0)
continue;
cpu = 2 * sat->nr + core;
sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
if (sens == NULL) {
printk(KERN_ERR "wf_sat_create: couldn't create power "
"sensor %d (no memory)\n", cpu);
continue;
}
sens->index = vsens[core];
sens->index2 = isens[core];
sens->shift = 0;
sens->sat = sat;
atomic_inc(&sat->refcnt);
sens->sens.ops = &wf_sat_ops;
sens->sens.name = (char *) (sens + 1);
snprintf(sens->sens.name, 16, "cpu-power-%d", cpu);
if (wf_register_sensor(&sens->sens)) {
atomic_dec(&sat->refcnt);
kfree(sens);
}
}
if (sat->nr >= 0)
sats[sat->nr] = sat;
return;
fail:
kfree(sat);
}
static int wf_sat_attach(struct i2c_adapter *adapter)
{
struct device_node *busnode, *dev = NULL;
struct pmac_i2c_bus *bus;
bus = pmac_i2c_adapter_to_bus(adapter);
if (bus == NULL)
return -ENODEV;
busnode = pmac_i2c_get_bus_node(bus);
while ((dev = of_get_next_child(busnode, dev)) != NULL)
if (device_is_compatible(dev, "smu-sat"))
wf_sat_create(adapter, dev);
return 0;
}
static int wf_sat_detach(struct i2c_client *client)
{
struct wf_sat *sat = i2c_to_sat(client);
/* XXX TODO */
sat->i2c.adapter = NULL;
return 0;
}
static int __init sat_sensors_init(void)
{
int err;
err = i2c_add_driver(&wf_sat_driver);
if (err < 0)
return err;
return 0;
}
static void __exit sat_sensors_exit(void)
{
i2c_del_driver(&wf_sat_driver);
}
module_init(sat_sensors_init);
/*module_exit(sat_sensors_exit); Uncomment when cleanup is implemented */
MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
MODULE_DESCRIPTION("SMU satellite sensors for PowerMac thermal control");
MODULE_LICENSE("GPL");
...@@ -220,14 +220,29 @@ static struct smu_ad_sensor *smu_ads_create(struct device_node *node) ...@@ -220,14 +220,29 @@ static struct smu_ad_sensor *smu_ads_create(struct device_node *node)
!strcmp(l, "CPU T-Diode")) { !strcmp(l, "CPU T-Diode")) {
ads->sens.ops = &smu_cputemp_ops; ads->sens.ops = &smu_cputemp_ops;
ads->sens.name = "cpu-temp"; ads->sens.name = "cpu-temp";
if (cpudiode == NULL) {
DBG("wf: cpudiode partition (%02x) not found\n",
SMU_SDB_CPUDIODE_ID);
goto fail;
}
} else if (!strcmp(c, "current-sensor") && } else if (!strcmp(c, "current-sensor") &&
!strcmp(l, "CPU Current")) { !strcmp(l, "CPU Current")) {
ads->sens.ops = &smu_cpuamp_ops; ads->sens.ops = &smu_cpuamp_ops;
ads->sens.name = "cpu-current"; ads->sens.name = "cpu-current";
if (cpuvcp == NULL) {
DBG("wf: cpuvcp partition (%02x) not found\n",
SMU_SDB_CPUVCP_ID);
goto fail;
}
} else if (!strcmp(c, "voltage-sensor") && } else if (!strcmp(c, "voltage-sensor") &&
!strcmp(l, "CPU Voltage")) { !strcmp(l, "CPU Voltage")) {
ads->sens.ops = &smu_cpuvolt_ops; ads->sens.ops = &smu_cpuvolt_ops;
ads->sens.name = "cpu-voltage"; ads->sens.name = "cpu-voltage";
if (cpuvcp == NULL) {
DBG("wf: cpuvcp partition (%02x) not found\n",
SMU_SDB_CPUVCP_ID);
goto fail;
}
} else if (!strcmp(c, "power-sensor") && } else if (!strcmp(c, "power-sensor") &&
!strcmp(l, "Slots Power")) { !strcmp(l, "Slots Power")) {
ads->sens.ops = &smu_slotspow_ops; ads->sens.ops = &smu_slotspow_ops;
...@@ -365,28 +380,21 @@ smu_cpu_power_create(struct wf_sensor *volts, struct wf_sensor *amps) ...@@ -365,28 +380,21 @@ smu_cpu_power_create(struct wf_sensor *volts, struct wf_sensor *amps)
return NULL; return NULL;
} }
static int smu_fetch_param_partitions(void) static void smu_fetch_param_partitions(void)
{ {
struct smu_sdbp_header *hdr; struct smu_sdbp_header *hdr;
/* Get CPU voltage/current/power calibration data */ /* Get CPU voltage/current/power calibration data */
hdr = smu_get_sdb_partition(SMU_SDB_CPUVCP_ID, NULL); hdr = smu_get_sdb_partition(SMU_SDB_CPUVCP_ID, NULL);
if (hdr == NULL) { if (hdr != NULL) {
DBG("wf: cpuvcp partition (%02x) not found\n",
SMU_SDB_CPUVCP_ID);
return -ENODEV;
}
cpuvcp = (struct smu_sdbp_cpuvcp *)&hdr[1]; cpuvcp = (struct smu_sdbp_cpuvcp *)&hdr[1];
/* Keep version around */ /* Keep version around */
cpuvcp_version = hdr->version; cpuvcp_version = hdr->version;
}
/* Get CPU diode calibration data */ /* Get CPU diode calibration data */
hdr = smu_get_sdb_partition(SMU_SDB_CPUDIODE_ID, NULL); hdr = smu_get_sdb_partition(SMU_SDB_CPUDIODE_ID, NULL);
if (hdr == NULL) { if (hdr != NULL)
DBG("wf: cpudiode partition (%02x) not found\n",
SMU_SDB_CPUDIODE_ID);
return -ENODEV;
}
cpudiode = (struct smu_sdbp_cpudiode *)&hdr[1]; cpudiode = (struct smu_sdbp_cpudiode *)&hdr[1];
/* Get slots power calibration data if any */ /* Get slots power calibration data if any */
...@@ -398,23 +406,18 @@ static int smu_fetch_param_partitions(void) ...@@ -398,23 +406,18 @@ static int smu_fetch_param_partitions(void)
hdr = smu_get_sdb_partition(SMU_SDB_DEBUG_SWITCHES_ID, NULL); hdr = smu_get_sdb_partition(SMU_SDB_DEBUG_SWITCHES_ID, NULL);
if (hdr != NULL) if (hdr != NULL)
debugswitches = (u8 *)&hdr[1]; debugswitches = (u8 *)&hdr[1];
return 0;
} }
static int __init smu_sensors_init(void) static int __init smu_sensors_init(void)
{ {
struct device_node *smu, *sensors, *s; struct device_node *smu, *sensors, *s;
struct smu_ad_sensor *volt_sensor = NULL, *curr_sensor = NULL; struct smu_ad_sensor *volt_sensor = NULL, *curr_sensor = NULL;
int rc;
if (!smu_present()) if (!smu_present())
return -ENODEV; return -ENODEV;
/* Get parameters partitions */ /* Get parameters partitions */
rc = smu_fetch_param_partitions(); smu_fetch_param_partitions();
if (rc)
return rc;
smu = of_find_node_by_type(NULL, "smu"); smu = of_find_node_by_type(NULL, "smu");
if (smu == NULL) if (smu == NULL)
......
...@@ -521,6 +521,11 @@ struct smu_sdbp_cpupiddata { ...@@ -521,6 +521,11 @@ struct smu_sdbp_cpupiddata {
extern struct smu_sdbp_header *smu_get_sdb_partition(int id, extern struct smu_sdbp_header *smu_get_sdb_partition(int id,
unsigned int *size); unsigned int *size);
/* Get "sdb" partition data from an SMU satellite */
extern struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id,
int id, unsigned int *size);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
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