ps3fb: don't keep the borders for non-fullscreen modes in XDR memory
[safe/jmp/linux-2.6] / drivers / hwmon / asb100.c
index d1856ac..9460dba 100644 (file)
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
-#include <linux/i2c-vid.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/jiffies.h>
+#include <linux/mutex.h>
 #include "lm75.h"
 
 /*
@@ -57,7 +57,7 @@
 static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(asb100);
+I2C_CLIENT_INSMOD_1(asb100);
 I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
        "{bus, clientaddr, subclientaddr1, subclientaddr2}");
 
@@ -143,7 +143,7 @@ static int FAN_FROM_REG(u8 val, int div)
 
 /* TEMP: 0.001C/bit (-128C to +127C)
    REG: 1C/bit, two's complement */
-static u8 TEMP_TO_REG(int temp)
+static u8 TEMP_TO_REG(long temp)
 {
        int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
        ntemp += (ntemp<0 ? -500 : 500);
@@ -182,11 +182,11 @@ static u8 DIV_TO_REG(long val)
    dynamically allocated, at the same time the client itself is allocated. */
 struct asb100_data {
        struct i2c_client client;
-       struct class_device *class_dev;
-       struct semaphore lock;
+       struct device *hwmon_dev;
+       struct mutex lock;
        enum chips type;
 
-       struct semaphore update_lock;
+       struct mutex update_lock;
        unsigned long last_updated;     /* In jiffies */
 
        /* array of 2 pointers to subclients */
@@ -218,10 +218,10 @@ static struct asb100_data *asb100_update_device(struct device *dev);
 static void asb100_init_client(struct i2c_client *client);
 
 static struct i2c_driver asb100_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "asb100",
+       .driver = {
+               .name   = "asb100",
+       },
        .id             = I2C_DRIVERID_ASB100,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = asb100_attach_adapter,
        .detach_client  = asb100_detach_client,
 };
@@ -246,11 +246,11 @@ static ssize_t set_in_##reg(struct device *dev, const char *buf, \
        struct asb100_data *data = i2c_get_clientdata(client); \
        unsigned long val = simple_strtoul(buf, NULL, 10); \
  \
-       down(&data->update_lock); \
+       mutex_lock(&data->update_lock); \
        data->in_##reg[nr] = IN_TO_REG(val); \
        asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
                data->in_##reg[nr]); \
-       up(&data->update_lock); \
+       mutex_unlock(&data->update_lock); \
        return count; \
 }
 
@@ -298,12 +298,6 @@ sysfs_in(4);
 sysfs_in(5);
 sysfs_in(6);
 
-#define device_create_file_in(client, offset) do { \
-       device_create_file(&client->dev, &dev_attr_in##offset##_input); \
-       device_create_file(&client->dev, &dev_attr_in##offset##_min); \
-       device_create_file(&client->dev, &dev_attr_in##offset##_max); \
-} while (0)
-
 /* 3 Fans */
 static ssize_t show_fan(struct device *dev, char *buf, int nr)
 {
@@ -332,16 +326,16 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
        struct asb100_data *data = i2c_get_clientdata(client);
        u32 val = simple_strtoul(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
        asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
 /* Note: we save and restore the fan minimum here, because its value is
    determined in part by the fan divisor.  This follows the principle of
-   least suprise; the user doesn't expect the fan minimum to change just
+   least surprise; the user doesn't expect the fan minimum to change just
    because the divisor changed. */
 static ssize_t set_fan_div(struct device *dev, const char *buf,
                                size_t count, int nr)
@@ -352,7 +346,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
        unsigned long val = simple_strtoul(buf, NULL, 10);
        int reg;
        
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        min = FAN_FROM_REG(data->fan_min[nr],
                        DIV_FROM_REG(data->fan_div[nr]));
@@ -382,7 +376,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
                FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
        asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return count;
 }
@@ -421,12 +415,6 @@ sysfs_fan(1);
 sysfs_fan(2);
 sysfs_fan(3);
 
-#define device_create_file_fan(client, offset) do { \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
-} while (0)
-
 /* 4 Temp. Sensors */
 static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
 {
@@ -460,9 +448,9 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
 { \
        struct i2c_client *client = to_i2c_client(dev); \
        struct asb100_data *data = i2c_get_clientdata(client); \
-       unsigned long val = simple_strtoul(buf, NULL, 10); \
+       long val = simple_strtol(buf, NULL, 10); \
  \
-       down(&data->update_lock); \
+       mutex_lock(&data->update_lock); \
        switch (nr) { \
        case 1: case 2: \
                data->reg[nr] = LM75_TEMP_TO_REG(val); \
@@ -473,7 +461,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
        } \
        asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
                        data->reg[nr]); \
-       up(&data->update_lock); \
+       mutex_unlock(&data->update_lock); \
        return count; \
 }
 
@@ -515,12 +503,6 @@ sysfs_temp(3);
 sysfs_temp(4);
 
 /* VID */
-#define device_create_file_temp(client, num) do { \
-       device_create_file(&client->dev, &dev_attr_temp##num##_input); \
-       device_create_file(&client->dev, &dev_attr_temp##num##_max); \
-       device_create_file(&client->dev, &dev_attr_temp##num##_max_hyst); \
-} while (0)
-
 static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct asb100_data *data = asb100_update_device(dev);
@@ -528,13 +510,11 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
 }
 
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
-#define device_create_file_vid(client) \
-device_create_file(&client->dev, &dev_attr_cpu0_vid)
 
 /* VRM */
 static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct asb100_data *data = asb100_update_device(dev);
+       struct asb100_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n", data->vrm);
 }
 
@@ -549,8 +529,6 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const
 
 /* Alarms */
 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
-#define device_create_file_vrm(client) \
-device_create_file(&client->dev, &dev_attr_vrm);
 
 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -559,8 +537,6 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
 }
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
-#define device_create_file_alarms(client) \
-device_create_file(&client->dev, &dev_attr_alarms)
 
 /* 1 PWM */
 static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
@@ -575,11 +551,11 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
        struct asb100_data *data = i2c_get_clientdata(client);
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->pwm &= 0x80; /* keep the enable bit */
        data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
        asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -596,21 +572,76 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
        struct asb100_data *data = i2c_get_clientdata(client);
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->pwm &= 0x0f; /* keep the duty cycle bits */
        data->pwm |= (val ? 0x80 : 0x00);
        asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
 static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
 static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
                show_pwm_enable1, set_pwm_enable1);
-#define device_create_file_pwm1(client) do { \
-       device_create_file(&new_client->dev, &dev_attr_pwm1); \
-       device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \
-} while (0)
+
+static struct attribute *asb100_attributes[] = {
+       &dev_attr_in0_input.attr,
+       &dev_attr_in0_min.attr,
+       &dev_attr_in0_max.attr,
+       &dev_attr_in1_input.attr,
+       &dev_attr_in1_min.attr,
+       &dev_attr_in1_max.attr,
+       &dev_attr_in2_input.attr,
+       &dev_attr_in2_min.attr,
+       &dev_attr_in2_max.attr,
+       &dev_attr_in3_input.attr,
+       &dev_attr_in3_min.attr,
+       &dev_attr_in3_max.attr,
+       &dev_attr_in4_input.attr,
+       &dev_attr_in4_min.attr,
+       &dev_attr_in4_max.attr,
+       &dev_attr_in5_input.attr,
+       &dev_attr_in5_min.attr,
+       &dev_attr_in5_max.attr,
+       &dev_attr_in6_input.attr,
+       &dev_attr_in6_min.attr,
+       &dev_attr_in6_max.attr,
+
+       &dev_attr_fan1_input.attr,
+       &dev_attr_fan1_min.attr,
+       &dev_attr_fan1_div.attr,
+       &dev_attr_fan2_input.attr,
+       &dev_attr_fan2_min.attr,
+       &dev_attr_fan2_div.attr,
+       &dev_attr_fan3_input.attr,
+       &dev_attr_fan3_min.attr,
+       &dev_attr_fan3_div.attr,
+
+       &dev_attr_temp1_input.attr,
+       &dev_attr_temp1_max.attr,
+       &dev_attr_temp1_max_hyst.attr,
+       &dev_attr_temp2_input.attr,
+       &dev_attr_temp2_max.attr,
+       &dev_attr_temp2_max_hyst.attr,
+       &dev_attr_temp3_input.attr,
+       &dev_attr_temp3_max.attr,
+       &dev_attr_temp3_max_hyst.attr,
+       &dev_attr_temp4_input.attr,
+       &dev_attr_temp4_max.attr,
+       &dev_attr_temp4_max_hyst.attr,
+
+       &dev_attr_cpu0_vid.attr,
+       &dev_attr_vrm.attr,
+       &dev_attr_alarms.attr,
+       &dev_attr_pwm1.attr,
+       &dev_attr_pwm1_enable.attr,
+
+       NULL
+};
+
+static const struct attribute_group asb100_group = {
+       .attrs = asb100_attributes,
+};
 
 /* This function is called when:
        asb100_driver is inserted (when this module is loaded), for each
@@ -621,7 +652,7 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, asb100_detect);
+       return i2c_probe(adapter, &addr_data, asb100_detect);
 }
 
 static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
@@ -630,19 +661,17 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
        int i, id, err;
        struct asb100_data *data = i2c_get_clientdata(new_client);
 
-       data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+       data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
        if (!(data->lm75[0])) {
                err = -ENOMEM;
                goto ERROR_SC_0;
        }
-       memset(data->lm75[0], 0x00, sizeof(struct i2c_client));
 
-       data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+       data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
        if (!(data->lm75[1])) {
                err = -ENOMEM;
                goto ERROR_SC_1;
        }
-       memset(data->lm75[1], 0x00, sizeof(struct i2c_client));
 
        id = i2c_adapter_id(adapter);
 
@@ -714,14 +743,6 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
        struct i2c_client *new_client;
        struct asb100_data *data;
 
-       /* asb100 is SMBus only */
-       if (i2c_is_isa_adapter(adapter)) {
-               pr_debug("asb100.o: detect failed, "
-                               "cannot attach to legacy adapter!\n");
-               err = -ENODEV;
-               goto ERROR0;
-       }
-
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
                pr_debug("asb100.o: detect failed, "
                                "smbus byte data not supported!\n");
@@ -733,15 +754,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
           client structure, even though we cannot fill it completely yet.
           But it allows us to access asb100_{read,write}_value. */
 
-       if (!(data = kmalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
-               pr_debug("asb100.o: detect failed, kmalloc failed!\n");
+       if (!(data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
+               pr_debug("asb100.o: detect failed, kzalloc failed!\n");
                err = -ENOMEM;
                goto ERROR0;
        }
-       memset(data, 0, sizeof(struct asb100_data));
 
        new_client = &data->client;
-       init_MUTEX(&data->lock);
+       mutex_init(&data->lock);
        i2c_set_clientdata(new_client, data);
        new_client->addr = address;
        new_client->adapter = adapter;
@@ -801,7 +821,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
        data->type = kind;
 
        data->valid = 0;
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
        if ((err = i2c_attach_client(new_client)))
@@ -821,38 +841,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
        data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
 
        /* Register sysfs hooks */
-       data->class_dev = hwmon_device_register(&new_client->dev);
-       if (IS_ERR(data->class_dev)) {
-               err = PTR_ERR(data->class_dev);
+       if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
                goto ERROR3;
-       }
-
-       device_create_file_in(new_client, 0);
-       device_create_file_in(new_client, 1);
-       device_create_file_in(new_client, 2);
-       device_create_file_in(new_client, 3);
-       device_create_file_in(new_client, 4);
-       device_create_file_in(new_client, 5);
-       device_create_file_in(new_client, 6);
-
-       device_create_file_fan(new_client, 1);
-       device_create_file_fan(new_client, 2);
-       device_create_file_fan(new_client, 3);
-
-       device_create_file_temp(new_client, 1);
-       device_create_file_temp(new_client, 2);
-       device_create_file_temp(new_client, 3);
-       device_create_file_temp(new_client, 4);
 
-       device_create_file_vid(new_client);
-       device_create_file_vrm(new_client);
-
-       device_create_file_alarms(new_client);
-
-       device_create_file_pwm1(new_client);
+       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto ERROR4;
+       }
 
        return 0;
 
+ERROR4:
+       sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
 ERROR3:
        i2c_detach_client(data->lm75[1]);
        i2c_detach_client(data->lm75[0]);
@@ -872,14 +873,13 @@ static int asb100_detach_client(struct i2c_client *client)
        int err;
 
        /* main client */
-       if (data)
-               hwmon_device_unregister(data->class_dev);
+       if (data) {
+               hwmon_device_unregister(data->hwmon_dev);
+               sysfs_remove_group(&client->dev.kobj, &asb100_group);
+       }
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "client deregistration failed; "
-                       "client not detached.\n");
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
        /* main client */
        if (data)
@@ -900,7 +900,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
        struct i2c_client *cl;
        int res, bank;
 
-       down(&data->lock);
+       mutex_lock(&data->lock);
 
        bank = (reg >> 8) & 0x0f;
        if (bank > 2)
@@ -934,7 +934,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
        if (bank > 2)
                i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
 
-       up(&data->lock);
+       mutex_unlock(&data->lock);
 
        return res;
 }
@@ -945,7 +945,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
        struct i2c_client *cl;
        int bank;
 
-       down(&data->lock);
+       mutex_lock(&data->lock);
 
        bank = (reg >> 8) & 0x0f;
        if (bank > 2)
@@ -975,7 +975,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
        if (bank > 2)
                i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
 
-       up(&data->lock);
+       mutex_unlock(&data->lock);
 }
 
 static void asb100_init_client(struct i2c_client *client)
@@ -985,7 +985,7 @@ static void asb100_init_client(struct i2c_client *client)
 
        vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f;
        vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4;
-       data->vrm = i2c_which_vrm();
+       data->vrm = vid_which_vrm();
        vid = vid_from_reg(vid, data->vrm);
 
        /* Start monitoring */
@@ -999,7 +999,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
        struct asb100_data *data = i2c_get_clientdata(client);
        int i;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
                || !data->valid) {
@@ -1057,7 +1057,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
                dev_dbg(&client->dev, "... device update complete\n");
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }