]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/hwmon/fschmd.c
hwmon: (fschmd) Cleanups for watchdog support
[linux-2.6-omap-h63xx.git] / drivers / hwmon / fschmd.c
index bd89d270a5ed2b7fcfcd6eac5ede75c397b6cb9b..c188b71350254843ca6117044d4d0d52298fd76c 100644 (file)
@@ -1,6 +1,6 @@
 /* fschmd.c
  *
- * Copyright (C) 2007 Hans de Goede <j.w.r.degoede@hhs.nl>
+ * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -63,7 +63,7 @@ I2C_CLIENT_INSMOD_5(fscpos, fscher, fscscy, fschrc, fschmd);
 #define FSCHMD_REG_EVENT_STATE         0x04
 #define FSCHMD_REG_CONTROL             0x05
 
-#define FSCHMD_CONTROL_ALERT_LED_MASK  0x01
+#define FSCHMD_CONTROL_ALERT_LED       0x01
 
 /* watchdog (support to be implemented) */
 #define FSCHMD_REG_WDOG_PRESET         0x28
@@ -115,8 +115,8 @@ static const u8 FSCHMD_REG_FAN_RIPPLE[5][6] = {
 static const int FSCHMD_NO_FAN_SENSORS[5] = { 3, 3, 6, 4, 5 };
 
 /* Fan status register bitmasks */
-#define FSCHMD_FAN_ALARM_MASK          0x04 /* called fault by FSC! */
-#define FSCHMD_FAN_NOT_PRESENT_MASK    0x08 /* not documented */
+#define FSCHMD_FAN_ALARM       0x04 /* called fault by FSC! */
+#define FSCHMD_FAN_NOT_PRESENT 0x08 /* not documented */
 
 
 /* actual temperature registers */
@@ -158,33 +158,47 @@ static const u8 FSCHER_REG_TEMP_AUTOP2[] =        { 0x75, 0x85, 0x95 }; */
 static const int FSCHMD_NO_TEMP_SENSORS[5] = { 3, 3, 4, 3, 5 };
 
 /* temp status register bitmasks */
-#define FSCHMD_TEMP_WORKING_MASK       0x01
-#define FSCHMD_TEMP_ALERT_MASK         0x02
+#define FSCHMD_TEMP_WORKING    0x01
+#define FSCHMD_TEMP_ALERT      0x02
 /* there only really is an alarm if the sensor is working and alert == 1 */
 #define FSCHMD_TEMP_ALARM_MASK \
-       (FSCHMD_TEMP_WORKING_MASK | FSCHMD_TEMP_ALERT_MASK)
-
-/* our driver name */
-#define FSCHMD_NAME "fschmd"
+       (FSCHMD_TEMP_WORKING | FSCHMD_TEMP_ALERT)
 
 /*
  * Functions declarations
  */
 
-static int fschmd_attach_adapter(struct i2c_adapter *adapter);
-static int fschmd_detach_client(struct i2c_client *client);
+static int fschmd_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id);
+static int fschmd_detect(struct i2c_client *client, int kind,
+                        struct i2c_board_info *info);
+static int fschmd_remove(struct i2c_client *client);
 static struct fschmd_data *fschmd_update_device(struct device *dev);
 
 /*
  * Driver data (common to all clients)
  */
 
+static const struct i2c_device_id fschmd_id[] = {
+       { "fscpos", fscpos },
+       { "fscher", fscher },
+       { "fscscy", fscscy },
+       { "fschrc", fschrc },
+       { "fschmd", fschmd },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, fschmd_id);
+
 static struct i2c_driver fschmd_driver = {
+       .class          = I2C_CLASS_HWMON,
        .driver = {
-               .name   = FSCHMD_NAME,
+               .name   = "fschmd",
        },
-       .attach_adapter = fschmd_attach_adapter,
-       .detach_client  = fschmd_detach_client,
+       .probe          = fschmd_probe,
+       .remove         = fschmd_remove,
+       .id_table       = fschmd_id,
+       .detect         = fschmd_detect,
+       .address_data   = &addr_data,
 };
 
 /*
@@ -192,7 +206,6 @@ static struct i2c_driver fschmd_driver = {
  */
 
 struct fschmd_data {
-       struct i2c_client client;
        struct device *hwmon_dev;
        struct mutex update_lock;
        int kind;
@@ -269,7 +282,7 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
        v = SENSORS_LIMIT(v, -128, 127) + 128;
 
        mutex_lock(&data->update_lock);
-       i2c_smbus_write_byte_data(&data->client,
+       i2c_smbus_write_byte_data(to_i2c_client(dev),
                FSCHMD_REG_TEMP_LIMIT[data->kind][index], v);
        data->temp_max[index] = v;
        mutex_unlock(&data->update_lock);
@@ -284,7 +297,7 @@ static ssize_t show_temp_fault(struct device *dev,
        struct fschmd_data *data = fschmd_update_device(dev);
 
        /* bit 0 set means sensor working ok, so no fault! */
-       if (data->temp_status[index] & FSCHMD_TEMP_WORKING_MASK)
+       if (data->temp_status[index] & FSCHMD_TEMP_WORKING)
                return sprintf(buf, "0\n");
        else
                return sprintf(buf, "1\n");
@@ -346,14 +359,14 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute
 
        mutex_lock(&data->update_lock);
 
-       reg = i2c_smbus_read_byte_data(&data->client,
+       reg = i2c_smbus_read_byte_data(to_i2c_client(dev),
                FSCHMD_REG_FAN_RIPPLE[data->kind][index]);
 
        /* bits 2..7 reserved => mask with 0x03 */
        reg &= ~0x03;
        reg |= v;
 
-       i2c_smbus_write_byte_data(&data->client,
+       i2c_smbus_write_byte_data(to_i2c_client(dev),
                FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg);
 
        data->fan_ripple[index] = reg;
@@ -369,7 +382,7 @@ static ssize_t show_fan_alarm(struct device *dev,
        int index = to_sensor_dev_attr(devattr)->index;
        struct fschmd_data *data = fschmd_update_device(dev);
 
-       if (data->fan_status[index] & FSCHMD_FAN_ALARM_MASK)
+       if (data->fan_status[index] & FSCHMD_FAN_ALARM)
                return sprintf(buf, "1\n");
        else
                return sprintf(buf, "0\n");
@@ -381,7 +394,7 @@ static ssize_t show_fan_fault(struct device *dev,
        int index = to_sensor_dev_attr(devattr)->index;
        struct fschmd_data *data = fschmd_update_device(dev);
 
-       if (data->fan_status[index] & FSCHMD_FAN_NOT_PRESENT_MASK)
+       if (data->fan_status[index] & FSCHMD_FAN_NOT_PRESENT)
                return sprintf(buf, "1\n");
        else
                return sprintf(buf, "0\n");
@@ -416,7 +429,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
 
        mutex_lock(&data->update_lock);
 
-       i2c_smbus_write_byte_data(&data->client,
+       i2c_smbus_write_byte_data(to_i2c_client(dev),
                FSCHMD_REG_FAN_MIN[data->kind][index], v);
        data->fan_min[index] = v;
 
@@ -433,7 +446,7 @@ static ssize_t show_alert_led(struct device *dev,
 {
        struct fschmd_data *data = fschmd_update_device(dev);
 
-       if (data->global_control & FSCHMD_CONTROL_ALERT_LED_MASK)
+       if (data->global_control & FSCHMD_CONTROL_ALERT_LED)
                return sprintf(buf, "1\n");
        else
                return sprintf(buf, "0\n");
@@ -448,14 +461,14 @@ static ssize_t store_alert_led(struct device *dev,
 
        mutex_lock(&data->update_lock);
 
-       reg = i2c_smbus_read_byte_data(&data->client, FSCHMD_REG_CONTROL);
+       reg = i2c_smbus_read_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL);
 
        if (v)
-               reg |= FSCHMD_CONTROL_ALERT_LED_MASK;
+               reg |= FSCHMD_CONTROL_ALERT_LED;
        else
-               reg &= ~FSCHMD_CONTROL_ALERT_LED_MASK;
+               reg &= ~FSCHMD_CONTROL_ALERT_LED;
 
-       i2c_smbus_write_byte_data(&data->client, FSCHMD_REG_CONTROL, reg);
+       i2c_smbus_write_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL, reg);
 
        data->global_control = reg;
 
@@ -600,32 +613,15 @@ static void fschmd_dmi_decode(const struct dmi_header *header)
        }
 }
 
-static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
+static int fschmd_detect(struct i2c_client *client, int kind,
+                        struct i2c_board_info *info)
 {
-       struct i2c_client *client;
-       struct fschmd_data *data;
-       u8 revision;
-       const char * const names[5] = { "Poseidon", "Hermes", "Scylla",
-                                       "Heracles", "Heimdall" };
+       struct i2c_adapter *adapter = client->adapter;
        const char * const client_names[5] = { "fscpos", "fscher", "fscscy",
                                                "fschrc", "fschmd" };
-       int i, err = 0;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-               return 0;
-
-       /* OK. For now, we presume we have a valid client. We now create the
-        * client structure, even though we cannot fill it completely yet.
-        * But it allows us to access i2c_smbus_read_byte_data. */
-       if (!(data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL)))
-               return -ENOMEM;
-
-       client = &data->client;
-       i2c_set_clientdata(client, data);
-       client->addr = address;
-       client->adapter = adapter;
-       client->driver = &fschmd_driver;
-       mutex_init(&data->update_lock);
+               return -ENODEV;
 
        /* Detect & Identify the chip */
        if (kind <= 0) {
@@ -650,9 +646,31 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
                else if (!strcmp(id, "HMD"))
                        kind = fschmd;
                else
-                       goto exit_free;
+                       return -ENODEV;
        }
 
+       strlcpy(info->type, client_names[kind - 1], I2C_NAME_SIZE);
+
+       return 0;
+}
+
+static int fschmd_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct fschmd_data *data;
+       u8 revision;
+       const char * const names[5] = { "Poseidon", "Hermes", "Scylla",
+                                       "Heracles", "Heimdall" };
+       int i, err;
+       enum chips kind = id->driver_data;
+
+       data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       i2c_set_clientdata(client, data);
+       mutex_init(&data->update_lock);
+
        if (kind == fscpos) {
                /* The Poseidon has hardwired temp limits, fill these
                   in for the alarm resetting code */
@@ -662,11 +680,11 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Read the special DMI table for fscher and newer chips */
-       if (kind == fscher || kind >= fschrc) {
+       if ((kind == fscher || kind >= fschrc) && dmi_vref == -1) {
                dmi_walk(fschmd_dmi_decode);
                if (dmi_vref == -1) {
-                       printk(KERN_WARNING FSCHMD_NAME
-                               "Couldn't get voltage scaling factors from "
+                       dev_warn(&client->dev,
+                               "Couldn't get voltage scaling factors from "
                                "BIOS DMI table, using builtin defaults\n");
                        dmi_vref = 33;
                }
@@ -674,11 +692,6 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
 
        /* i2c kind goes from 1-5, we want from 0-4 to address arrays */
        data->kind = kind - 1;
-       strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE);
-
-       /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(client)))
-               goto exit_free;
 
        for (i = 0; i < ARRAY_SIZE(fschmd_attr); i++) {
                err = device_create_file(&client->dev,
@@ -720,31 +733,20 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
-       printk(KERN_INFO FSCHMD_NAME ": Detected FSC %s chip, revision: %d\n",
+       dev_info(&client->dev, "Detected FSC %s chip, revision: %d\n",
                names[data->kind], (int) revision);
 
        return 0;
 
 exit_detach:
-       fschmd_detach_client(client); /* will also free data for us */
-       return err;
-
-exit_free:
-       kfree(data);
+       fschmd_remove(client); /* will also free data for us */
        return err;
 }
 
-static int fschmd_attach_adapter(struct i2c_adapter *adapter)
-{
-       if (!(adapter->class & I2C_CLASS_HWMON))
-               return 0;
-       return i2c_probe(adapter, &addr_data, fschmd_detect);
-}
-
-static int fschmd_detach_client(struct i2c_client *client)
+static int fschmd_remove(struct i2c_client *client)
 {
        struct fschmd_data *data = i2c_get_clientdata(client);
-       int i, err;
+       int i;
 
        /* Check if registered in case we're called from fschmd_detect
           to cleanup after an error */
@@ -760,9 +762,6 @@ static int fschmd_detach_client(struct i2c_client *client)
                device_remove_file(&client->dev,
                                        &fschmd_fan_attr[i].dev_attr);
 
-       if ((err = i2c_detach_client(client)))
-               return err;
-
        kfree(data);
        return 0;
 }
@@ -796,7 +795,7 @@ static struct fschmd_data *fschmd_update_device(struct device *dev)
                                        data->temp_act[i] < data->temp_max[i])
                                i2c_smbus_write_byte_data(client,
                                        FSCHMD_REG_TEMP_STATE[data->kind][i],
-                                       FSCHMD_TEMP_ALERT_MASK);
+                                       FSCHMD_TEMP_ALERT);
                }
 
                for (i = 0; i < FSCHMD_NO_FAN_SENSORS[data->kind]; i++) {
@@ -814,11 +813,11 @@ static struct fschmd_data *fschmd_update_device(struct device *dev)
                                        FSCHMD_REG_FAN_MIN[data->kind][i]);
 
                        /* reset fan status if speed is back to > 0 */
-                       if ((data->fan_status[i] & FSCHMD_FAN_ALARM_MASK) &&
+                       if ((data->fan_status[i] & FSCHMD_FAN_ALARM) &&
                                        data->fan_act[i])
                                i2c_smbus_write_byte_data(client,
                                        FSCHMD_REG_FAN_STATE[data->kind][i],
-                                       FSCHMD_FAN_ALARM_MASK);
+                                       FSCHMD_FAN_ALARM);
                }
 
                for (i = 0; i < 3; i++)
@@ -855,7 +854,7 @@ static void __exit fschmd_exit(void)
        i2c_del_driver(&fschmd_driver);
 }
 
-MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
 MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles and "
                        "Heimdall driver");
 MODULE_LICENSE("GPL");