Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[pandora-kernel.git] / drivers / hwmon / lm70.c
index 6ba8473..d435f00 100644 (file)
 #include <linux/err.h>
 #include <linux/sysfs.h>
 #include <linux/hwmon.h>
+#include <linux/mutex.h>
 #include <linux/spi/spi.h>
-#include <asm/semaphore.h>
+
 
 #define DRVNAME                "lm70"
 
 struct lm70 {
-       struct class_device *cdev;
-       struct semaphore sem;
+       struct device *hwmon_dev;
+       struct mutex lock;
 };
 
 /* sysfs hook function */
@@ -51,7 +52,7 @@ static ssize_t lm70_sense_temp(struct device *dev,
        s16 raw=0;
        struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
 
-       if (down_interruptible(&p_lm70->sem))
+       if (mutex_lock_interruptible(&p_lm70->lock))
                return -ERESTARTSYS;
 
        /*
@@ -81,14 +82,22 @@ static ssize_t lm70_sense_temp(struct device *dev,
         * So it's equivalent to multiplying by 0.25 * 1000 = 250.
         */
        val = ((int)raw/32) * 250;
-       status = sprintf(buf, "%+d\n", val); /* millidegrees Celsius */
+       status = sprintf(buf, "%d\n", val); /* millidegrees Celsius */
 out:
-       up(&p_lm70->sem);
+       mutex_unlock(&p_lm70->lock);
        return status;
 }
 
 static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL);
 
+static ssize_t lm70_show_name(struct device *dev, struct device_attribute
+                             *devattr, char *buf)
+{
+       return sprintf(buf, "lm70\n");
+}
+
+static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
+
 /*----------------------------------------------------------------------*/
 
 static int __devinit lm70_probe(struct spi_device *spi)
@@ -96,22 +105,27 @@ static int __devinit lm70_probe(struct spi_device *spi)
        struct lm70 *p_lm70;
        int status;
 
+       /* signaling is SPI_MODE_0 on a 3-wire link (shared SI/SO) */
+       if ((spi->mode & (SPI_CPOL|SPI_CPHA)) || !(spi->mode & SPI_3WIRE))
+               return -EINVAL;
+
        p_lm70 = kzalloc(sizeof *p_lm70, GFP_KERNEL);
        if (!p_lm70)
                return -ENOMEM;
 
-       init_MUTEX(&p_lm70->sem);
+       mutex_init(&p_lm70->lock);
 
        /* sysfs hook */
-       p_lm70->cdev = hwmon_device_register(&spi->dev);
-       if (IS_ERR(p_lm70->cdev)) {
+       p_lm70->hwmon_dev = hwmon_device_register(&spi->dev);
+       if (IS_ERR(p_lm70->hwmon_dev)) {
                dev_dbg(&spi->dev, "hwmon_device_register failed.\n");
-               status = PTR_ERR(p_lm70->cdev);
+               status = PTR_ERR(p_lm70->hwmon_dev);
                goto out_dev_reg_failed;
        }
        dev_set_drvdata(&spi->dev, p_lm70);
 
-       if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) {
+       if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
+        || (status = device_create_file(&spi->dev, &dev_attr_name))) {
                dev_dbg(&spi->dev, "device_create_file failure.\n");
                goto out_dev_create_file_failed;
        }
@@ -119,19 +133,21 @@ static int __devinit lm70_probe(struct spi_device *spi)
        return 0;
 
 out_dev_create_file_failed:
-       hwmon_device_unregister(p_lm70->cdev);
+       device_remove_file(&spi->dev, &dev_attr_temp1_input);
+       hwmon_device_unregister(p_lm70->hwmon_dev);
 out_dev_reg_failed:
        dev_set_drvdata(&spi->dev, NULL);
        kfree(p_lm70);
        return status;
 }
 
-static int __exit lm70_remove(struct spi_device *spi)
+static int __devexit lm70_remove(struct spi_device *spi)
 {
        struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
 
        device_remove_file(&spi->dev, &dev_attr_temp1_input);
-       hwmon_device_unregister(p_lm70->cdev);
+       device_remove_file(&spi->dev, &dev_attr_name);
+       hwmon_device_unregister(p_lm70->hwmon_dev);
        dev_set_drvdata(&spi->dev, NULL);
        kfree(p_lm70);