X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fmacintosh%2Ftherm_adt746x.c;h=c0621d50c8a0ca1281881b68d587f1c8be81ec96;hb=75ee034addc9ac3f6a38a9e6b30e9b54be15d4e5;hp=c9ca1118e449207c2dca58a742b0ddd204a556d7;hpb=3e1d1d28d99dabe63c64f7f40f1ca1d646de1f73;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c index c9ca111..c0621d5 100644 --- a/drivers/macintosh/therm_adt746x.c +++ b/drivers/macintosh/therm_adt746x.c @@ -9,7 +9,6 @@ * */ -#include #include #include #include @@ -20,18 +19,18 @@ #include #include #include -#include #include #include #include #include +#include +#include #include #include #include #include #include -#include #undef DEBUG @@ -48,10 +47,11 @@ static u8 FAN_SPD_SET[2] = {0x30, 0x31}; static u8 default_limits_local[3] = {70, 50, 70}; /* local, sensor1, sensor2 */ static u8 default_limits_chip[3] = {80, 65, 80}; /* local, sensor1, sensor2 */ -static char *sensor_location[3] = {NULL, NULL, NULL}; +static const char *sensor_location[3]; -static int limit_adjust = 0; +static int limit_adjust; static int fan_speed = -1; +static int verbose; MODULE_AUTHOR("Colin Leroy "); MODULE_DESCRIPTION("Driver for ADT746x thermostat in iBook G4 and " @@ -66,6 +66,10 @@ module_param(fan_speed, int, 0644); MODULE_PARM_DESC(fan_speed,"Specify starting fan speed (0-255) " "(default 64)"); +module_param(verbose, bool, 0); +MODULE_PARM_DESC(verbose,"Verbose log operations " + "(default 0)"); + struct thermostat { struct i2c_client clt; u8 temps[3]; @@ -149,13 +153,13 @@ detach_thermostat(struct i2c_adapter *adapter) if (thread_therm != NULL) { kthread_stop(thread_therm); } - + printk(KERN_INFO "adt746x: Putting max temperatures back from " "%d, %d, %d to %d, %d, %d\n", th->limits[0], th->limits[1], th->limits[2], th->initial_limits[0], th->initial_limits[1], th->initial_limits[2]); - + for (i = 0; i < 3; i++) write_reg(th, LIMIT_REG[i], th->initial_limits[i]); @@ -171,9 +175,9 @@ detach_thermostat(struct i2c_adapter *adapter) } static struct i2c_driver thermostat_driver = { - .owner = THIS_MODULE, - .name = "therm_adt746x", - .flags = I2C_DF_NOTIFY, + .driver = { + .name = "therm_adt746x", + }, .attach_adapter = attach_thermostat, .detach_adapter = detach_thermostat, }; @@ -212,12 +216,14 @@ static void write_fan_speed(struct thermostat *th, int speed, int fan) return; if (th->last_speed[fan] != speed) { - if (speed == -1) - printk(KERN_DEBUG "adt746x: Setting speed to automatic " - "for %s fan.\n", sensor_location[fan+1]); - else - printk(KERN_DEBUG "adt746x: Setting speed to %d " - "for %s fan.\n", speed, sensor_location[fan+1]); + if (verbose) { + if (speed == -1) + printk(KERN_DEBUG "adt746x: Setting speed to automatic " + "for %s fan.\n", sensor_location[fan+1]); + else + printk(KERN_DEBUG "adt746x: Setting speed to %d " + "for %s fan.\n", speed, sensor_location[fan+1]); + } } else return; @@ -298,10 +304,11 @@ static void update_fans_speed (struct thermostat *th) if (new_speed > 255) new_speed = 255; - printk(KERN_DEBUG "adt746x: setting fans speed to %d " - "(limit exceeded by %d on %s) \n", - new_speed, var, - sensor_location[fan_number+1]); + if (verbose) + printk(KERN_DEBUG "adt746x: Setting fans speed to %d " + "(limit exceeded by %d on %s) \n", + new_speed, var, + sensor_location[fan_number+1]); write_both_fan_speed(th, new_speed); th->last_var[fan_number] = var; } else if (var < -2) { @@ -309,8 +316,9 @@ static void update_fans_speed (struct thermostat *th) * so cold (lastvar >= -1) */ if (i == 2 && lastvar < -1) { if (th->last_speed[fan_number] != 0) - printk(KERN_DEBUG "adt746x: Stopping " - "fans.\n"); + if (verbose) + printk(KERN_DEBUG "adt746x: Stopping " + "fans.\n"); write_both_fan_speed(th, 0); } } @@ -327,6 +335,7 @@ static int monitor_task(void *arg) { struct thermostat* th = arg; + set_freezable(); while(!kthread_should_stop()) { try_to_freeze(); msleep_interruptible(2000); @@ -370,13 +379,10 @@ static int attach_one_thermostat(struct i2c_adapter *adapter, int addr, if (thermostat) return 0; - th = (struct thermostat *) - kmalloc(sizeof(struct thermostat), GFP_KERNEL); - + th = kzalloc(sizeof(struct thermostat), GFP_KERNEL); if (!th) return -ENOMEM; - memset(th, 0, sizeof(*th)); th->clt.addr = addr; th->clt.adapter = adapter; th->clt.driver = &thermostat_driver; @@ -406,7 +412,7 @@ static int attach_one_thermostat(struct i2c_adapter *adapter, int addr, th->initial_limits[i] = read_reg(th, LIMIT_REG[i]); set_limit(th, i); } - + printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d" " to %d, %d, %d\n", th->initial_limits[0], th->initial_limits[1], @@ -492,8 +498,8 @@ static ssize_t store_##name(struct device *dev, struct device_attribute *attr, c #define BUILD_STORE_FUNC_INT(name, data) \ static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \ { \ - u32 val; \ - val = simple_strtoul(buf, NULL, 10); \ + int val; \ + val = simple_strtol(buf, NULL, 10); \ if (val < 0 || val > 255) \ return -EINVAL; \ printk(KERN_INFO "Setting specified fan speed to %d\n", val); \ @@ -545,28 +551,35 @@ static int __init thermostat_init(void) { struct device_node* np; - u32 *prop; + const u32 *prop; int i = 0, offset = 0; - + int err; + np = of_find_node_by_name(NULL, "fan"); if (!np) return -ENODEV; - if (device_is_compatible(np, "adt7460")) + if (of_device_is_compatible(np, "adt7460")) therm_type = ADT7460; - else if (device_is_compatible(np, "adt7467")) + else if (of_device_is_compatible(np, "adt7467")) therm_type = ADT7467; - else + else { + of_node_put(np); return -ENODEV; + } - prop = (u32 *)get_property(np, "hwsensor-params-version", NULL); + prop = of_get_property(np, "hwsensor-params-version", NULL); printk(KERN_INFO "adt746x: version %d (%ssupported)\n", *prop, (*prop == 1)?"":"un"); - if (*prop != 1) + if (*prop != 1) { + of_node_put(np); return -ENODEV; + } - prop = (u32 *)get_property(np, "reg", NULL); - if (!prop) + prop = of_get_property(np, "reg", NULL); + if (!prop) { + of_node_put(np); return -ENODEV; + } /* look for bus either by path or using "reg" */ if (strstr(np->full_name, "/i2c-bus@") != NULL) { @@ -582,9 +595,9 @@ thermostat_init(void) "limit_adjust: %d, fan_speed: %d\n", therm_bus, therm_address, limit_adjust, fan_speed); - if (get_property(np, "hwsensor-location", NULL)) { + if (of_get_property(np, "hwsensor-location", NULL)) { for (i = 0; i < 3; i++) { - sensor_location[i] = get_property(np, + sensor_location[i] = of_get_property(np, "hwsensor-location", NULL) + offset; if (sensor_location[i] == NULL) @@ -599,27 +612,31 @@ thermostat_init(void) sensor_location[2] = "?"; } - of_dev = of_platform_device_create(np, "temperatures"); - + of_dev = of_platform_device_create(np, "temperatures", NULL); + of_node_put(np); + if (of_dev == NULL) { printk(KERN_ERR "Can't register temperatures device !\n"); return -ENODEV; } - - device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); - device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); - device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); - device_create_file(&of_dev->dev, &dev_attr_sensor2_limit); - device_create_file(&of_dev->dev, &dev_attr_sensor1_location); - device_create_file(&of_dev->dev, &dev_attr_sensor2_location); - device_create_file(&of_dev->dev, &dev_attr_limit_adjust); - device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed); - device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed); + + err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_limit); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_location); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_location); + err |= device_create_file(&of_dev->dev, &dev_attr_limit_adjust); + err |= device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed); if(therm_type == ADT7460) - device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed); + err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed); + if (err) + printk(KERN_WARNING + "Failed to create tempertaure attribute file(s).\n"); -#ifndef CONFIG_I2C_KEYWEST - request_module("i2c-keywest"); +#ifndef CONFIG_I2C_POWERMAC + request_module("i2c-powermac"); #endif return i2c_add_driver(&thermostat_driver);