drivers: Push down BKL into various drivers
[safe/jmp/linux-2.6] / drivers / hwmon / fschmd.c
index ea955ed..b7ca2a9 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
+#include <linux/smp_lock.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
@@ -56,7 +57,8 @@ static int nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, int, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
        __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
-I2C_CLIENT_INSMOD_7(fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl);
+
+enum chips { fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl };
 
 /*
  * The FSCHMD registers and other defines
@@ -221,7 +223,7 @@ static const int FSCHMD_NO_TEMP_SENSORS[7] = { 3, 3, 4, 3, 5, 5, 11 };
 
 static int fschmd_probe(struct i2c_client *client,
                        const struct i2c_device_id *id);
-static int fschmd_detect(struct i2c_client *client, int kind,
+static int fschmd_detect(struct i2c_client *client,
                         struct i2c_board_info *info);
 static int fschmd_remove(struct i2c_client *client);
 static struct fschmd_data *fschmd_update_device(struct device *dev);
@@ -251,7 +253,7 @@ static struct i2c_driver fschmd_driver = {
        .remove         = fschmd_remove,
        .id_table       = fschmd_id,
        .detect         = fschmd_detect,
-       .address_data   = &addr_data,
+       .address_list   = normal_i2c,
 };
 
 /*
@@ -266,7 +268,7 @@ struct fschmd_data {
        struct list_head list; /* member of the watchdog_data_list */
        struct kref kref;
        struct miscdevice watchdog_miscdev;
-       int kind;
+       enum chips kind;
        unsigned long watchdog_is_open;
        char watchdog_expect_close;
        char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
@@ -324,8 +326,7 @@ static ssize_t show_in_value(struct device *dev,
        int index = to_sensor_dev_attr(devattr)->index;
        struct fschmd_data *data = fschmd_update_device(dev);
 
-       /* fscher / fschrc - 1 as data->kind is an array index, not a chips */
-       if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
+       if (data->kind == fscher || data->kind >= fschrc)
                return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
                        dmi_mult[index]) / 255 + dmi_offset[index]);
        else
@@ -491,7 +492,7 @@ static ssize_t show_pwm_auto_point1_pwm(struct device *dev,
        int val = data->fan_min[index];
 
        /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */
-       if (val || data->kind == fscsyl - 1)
+       if (val || data->kind == fscsyl)
                val = val / 2 + 128;
 
        return sprintf(buf, "%d\n", val);
@@ -505,7 +506,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
        unsigned long v = simple_strtoul(buf, NULL, 10);
 
        /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
-       if (v || data->kind == fscsyl - 1) {
+       if (v || data->kind == fscsyl) {
                v = SENSORS_LIMIT(v, 128, 255);
                v = (v - 128) * 2 + 1;
        }
@@ -767,6 +768,7 @@ leave:
 static int watchdog_open(struct inode *inode, struct file *filp)
 {
        struct fschmd_data *pos, *data = NULL;
+       int watchdog_is_open;
 
        /* We get called from drivers/char/misc.c with misc_mtx hold, and we
           call misc_register() from fschmd_probe() with watchdog_data_mutex
@@ -781,10 +783,12 @@ static int watchdog_open(struct inode *inode, struct file *filp)
                }
        }
        /* Note we can never not have found data, so we don't check for this */
-       kref_get(&data->kref);
+       watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
+       if (!watchdog_is_open)
+               kref_get(&data->kref);
        mutex_unlock(&watchdog_data_mutex);
 
-       if (test_and_set_bit(0, &data->watchdog_is_open))
+       if (watchdog_is_open)
                return -EBUSY;
 
        /* Start the watchdog */
@@ -819,7 +823,7 @@ static int watchdog_release(struct inode *inode, struct file *filp)
 static ssize_t watchdog_write(struct file *filp, const char __user *buf,
        size_t count, loff_t *offset)
 {
-       size_t ret;
+       int ret;
        struct fschmd_data *data = filp->private_data;
 
        if (count) {
@@ -844,8 +848,7 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
        return count;
 }
 
-static int watchdog_ioctl(struct inode *inode, struct file *filp,
-       unsigned int cmd, unsigned long arg)
+static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        static struct watchdog_info ident = {
                .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
@@ -855,6 +858,7 @@ static int watchdog_ioctl(struct inode *inode, struct file *filp,
        int i, ret = 0;
        struct fschmd_data *data = filp->private_data;
 
+       lock_kernel();
        switch (cmd) {
        case WDIOC_GETSUPPORT:
                ident.firmware_version = data->revision;
@@ -911,17 +915,17 @@ static int watchdog_ioctl(struct inode *inode, struct file *filp,
        default:
                ret = -ENOTTY;
        }
-
+       unlock_kernel();
        return ret;
 }
 
-static struct file_operations watchdog_fops = {
+static const struct file_operations watchdog_fops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .open = watchdog_open,
        .release = watchdog_release,
        .write = watchdog_write,
-       .ioctl = watchdog_ioctl,
+       .unlocked_ioctl = watchdog_ioctl,
 };
 
 
@@ -1000,45 +1004,40 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
        }
 }
 
-static int fschmd_detect(struct i2c_client *client, int kind,
+static int fschmd_detect(struct i2c_client *client,
                         struct i2c_board_info *info)
 {
+       enum chips kind;
        struct i2c_adapter *adapter = client->adapter;
+       char id[4];
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                return -ENODEV;
 
        /* Detect & Identify the chip */
-       if (kind <= 0) {
-               char id[4];
-
-               id[0] = i2c_smbus_read_byte_data(client,
-                               FSCHMD_REG_IDENT_0);
-               id[1] = i2c_smbus_read_byte_data(client,
-                               FSCHMD_REG_IDENT_1);
-               id[2] = i2c_smbus_read_byte_data(client,
-                               FSCHMD_REG_IDENT_2);
-               id[3] = '\0';
-
-               if (!strcmp(id, "PEG"))
-                       kind = fscpos;
-               else if (!strcmp(id, "HER"))
-                       kind = fscher;
-               else if (!strcmp(id, "SCY"))
-                       kind = fscscy;
-               else if (!strcmp(id, "HRC"))
-                       kind = fschrc;
-               else if (!strcmp(id, "HMD"))
-                       kind = fschmd;
-               else if (!strcmp(id, "HDS"))
-                       kind = fschds;
-               else if (!strcmp(id, "SYL"))
-                       kind = fscsyl;
-               else
-                       return -ENODEV;
-       }
+       id[0] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_0);
+       id[1] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_1);
+       id[2] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_2);
+       id[3] = '\0';
+
+       if (!strcmp(id, "PEG"))
+               kind = fscpos;
+       else if (!strcmp(id, "HER"))
+               kind = fscher;
+       else if (!strcmp(id, "SCY"))
+               kind = fscscy;
+       else if (!strcmp(id, "HRC"))
+               kind = fschrc;
+       else if (!strcmp(id, "HMD"))
+               kind = fschmd;
+       else if (!strcmp(id, "HDS"))
+               kind = fschds;
+       else if (!strcmp(id, "SYL"))
+               kind = fscsyl;
+       else
+               return -ENODEV;
 
-       strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE);
+       strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE);
 
        return 0;
 }
@@ -1066,6 +1065,7 @@ static int fschmd_probe(struct i2c_client *client,
           (where the client is found through a data ptr instead of the
           otherway around) */
        data->client = client;
+       data->kind = kind;
 
        if (kind == fscpos) {
                /* The Poseidon has hardwired temp limits, fill these
@@ -1086,9 +1086,6 @@ static int fschmd_probe(struct i2c_client *client,
                }
        }
 
-       /* i2c kind goes from 1-6, we want from 0-5 to address arrays */
-       data->kind = kind - 1;
-
        /* Read in some never changing registers */
        data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
        data->global_control = i2c_smbus_read_byte_data(client,