]> Pileus Git - ~andy/linux/blobdiff - drivers/hwmon/pc87427.c
Merge tag 'dlm-3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm
[~andy/linux] / drivers / hwmon / pc87427.c
index cb35461d52d9403f81d9c71507a9888040c6fb92..f185b1fa53e5eda188be4e57bc9272ac8c49abbc 100644 (file)
@@ -46,9 +46,11 @@ static struct platform_device *pdev;
 
 #define DRVNAME "pc87427"
 
-/* The lock mutex protects both the I/O accesses (needed because the
-   device is using banked registers) and the register cache (needed to keep
-   the data in the registers and the cache in sync at any time). */
+/*
+ * The lock mutex protects both the I/O accesses (needed because the
+ * device is using banked registers) and the register cache (needed to keep
+ * the data in the registers and the cache in sync at any time).
+ */
 struct pc87427_data {
        struct device *hwmon_dev;
        struct mutex lock;
@@ -173,10 +175,12 @@ static inline void pc87427_write8_bank(struct pc87427_data *data, u8 ldi,
 #define FAN_STATUS_LOSPD               (1 << 1)
 #define FAN_STATUS_MONEN               (1 << 0)
 
-/* Dedicated function to read all registers related to a given fan input.
-   This saves us quite a few locks and bank selections.
-   Must be called with data->lock held.
-   nr is from 0 to 7 */
+/*
+ * Dedicated function to read all registers related to a given fan input.
+ * This saves us quite a few locks and bank selections.
+ * Must be called with data->lock held.
+ * nr is from 0 to 7
+ */
 static void pc87427_readall_fan(struct pc87427_data *data, u8 nr)
 {
        int iobase = data->address[LD_FAN];
@@ -189,8 +193,10 @@ static void pc87427_readall_fan(struct pc87427_data *data, u8 nr)
        outb(data->fan_status[nr], iobase + PC87427_REG_FAN_STATUS);
 }
 
-/* The 2 LSB of fan speed registers are used for something different.
-   The actual 2 LSB of the measurements are not available. */
+/*
+ * The 2 LSB of fan speed registers are used for something different.
+ * The actual 2 LSB of the measurements are not available.
+ */
 static inline unsigned long fan_from_reg(u16 reg)
 {
        reg &= 0xfffc;
@@ -224,10 +230,12 @@ static inline u16 fan_to_reg(unsigned long val)
 #define PWM_MODE_OFF                   (2 << 4)
 #define PWM_MODE_ON                    (7 << 4)
 
-/* Dedicated function to read all registers related to a given PWM output.
-   This saves us quite a few locks and bank selections.
-   Must be called with data->lock held.
-   nr is from 0 to 3 */
+/*
+ * Dedicated function to read all registers related to a given PWM output.
+ * This saves us quite a few locks and bank selections.
+ * Must be called with data->lock held.
+ * nr is from 0 to 3
+ */
 static void pc87427_readall_pwm(struct pc87427_data *data, u8 nr)
 {
        int iobase = data->address[LD_FAN];
@@ -286,10 +294,12 @@ static inline u8 pwm_enable_to_reg(unsigned long val, u8 pwmval)
 #define TEMP_TYPE_REMOTE_DIODE         (2 << 5)
 #define TEMP_TYPE_LOCAL_DIODE          (3 << 5)
 
-/* Dedicated function to read all registers related to a given temperature
-   input. This saves us quite a few locks and bank selections.
-   Must be called with data->lock held.
-   nr is from 0 to 5 */
+/*
+ * Dedicated function to read all registers related to a given temperature
+ * input. This saves us quite a few locks and bank selections.
+ * Must be called with data->lock held.
+ * nr is from 0 to 5
+ */
 static void pc87427_readall_temp(struct pc87427_data *data, u8 nr)
 {
        int iobase = data->address[LD_TEMP];
@@ -318,8 +328,10 @@ static inline unsigned int temp_type_from_reg(u8 reg)
        }
 }
 
-/* We assume 8-bit thermal sensors; 9-bit thermal sensors are possible
-   too, but I have no idea how to figure out when they are used. */
+/*
+ * We assume 8-bit thermal sensors; 9-bit thermal sensors are possible
+ * too, but I have no idea how to figure out when they are used.
+ */
 static inline long temp_from_reg(s16 reg)
 {
        return reg * 1000 / 256;
@@ -423,9 +435,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
 
        mutex_lock(&data->lock);
        outb(BANK_FM(nr), iobase + PC87427_REG_BANK);
-       /* The low speed limit registers are read-only while monitoring
-          is enabled, so we have to disable monitoring, then change the
-          limit, and finally enable monitoring again. */
+       /*
+        * The low speed limit registers are read-only while monitoring
+        * is enabled, so we have to disable monitoring, then change the
+        * limit, and finally enable monitoring again.
+        */
        outb(0, iobase + PC87427_REG_FAN_STATUS);
        data->fan_min[nr] = fan_to_reg(val);
        outw(data->fan_min[nr], iobase + PC87427_REG_FAN_MIN);
@@ -542,8 +556,10 @@ static const struct attribute_group pc87427_group_fan[8] = {
        { .attrs = pc87427_attributes_fan[7] },
 };
 
-/* Must be called with data->lock held and pc87427_readall_pwm() freshly
-   called */
+/*
+ * Must be called with data->lock held and pc87427_readall_pwm() freshly
+ * called
+ */
 static void update_pwm_enable(struct pc87427_data *data, int nr, u8 mode)
 {
        int iobase = data->address[LD_FAN];
@@ -940,44 +956,28 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  * Device detection, attach and detach
  */
 
-static void pc87427_release_regions(struct platform_device *pdev, int count)
-{
-       struct resource *res;
-       int i;
-
-       for (i = 0; i < count; i++) {
-               res = platform_get_resource(pdev, IORESOURCE_IO, i);
-               release_region(res->start, resource_size(res));
-       }
-}
-
 static int __devinit pc87427_request_regions(struct platform_device *pdev,
                                             int count)
 {
        struct resource *res;
-       int i, err = 0;
+       int i;
 
        for (i = 0; i < count; i++) {
                res = platform_get_resource(pdev, IORESOURCE_IO, i);
                if (!res) {
-                       err = -ENOENT;
                        dev_err(&pdev->dev, "Missing resource #%d\n", i);
-                       break;
+                       return -ENOENT;
                }
-               if (!request_region(res->start, resource_size(res), DRVNAME)) {
-                       err = -EBUSY;
+               if (!devm_request_region(&pdev->dev, res->start,
+                                        resource_size(res), DRVNAME)) {
                        dev_err(&pdev->dev,
                                "Failed to request region 0x%lx-0x%lx\n",
                                (unsigned long)res->start,
                                (unsigned long)res->end);
-                       break;
+                       return -EBUSY;
                }
        }
-
-       if (err && i)
-               pc87427_release_regions(pdev, i);
-
-       return err;
+       return 0;
 }
 
 static void __devinit pc87427_init_device(struct device *dev)
@@ -1023,9 +1023,11 @@ static void __devinit pc87427_init_device(struct device *dev)
                if (reg & PWM_ENABLE_CTLEN)
                        data->pwm_enabled |= (1 << i);
 
-               /* We don't expose an interface to reconfigure the automatic
-                  fan control mode, so only allow to return to this mode if
-                  it was originally set. */
+               /*
+                * We don't expose an interface to reconfigure the automatic
+                * fan control mode, so only allow to return to this mode if
+                * it was originally set.
+                */
                if ((reg & PWM_ENABLE_MODE_MASK) == PWM_MODE_AUTO) {
                        dev_dbg(dev, "PWM%d is in automatic control mode\n",
                                i + 1);
@@ -1076,11 +1078,11 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
        struct pc87427_data *data;
        int i, err, res_count;
 
-       data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
+       data = devm_kzalloc(&pdev->dev, sizeof(struct pc87427_data),
+                           GFP_KERNEL);
        if (!data) {
-               err = -ENOMEM;
                pr_err("Out of memory\n");
-               goto exit;
+               return -ENOMEM;
        }
 
        data->address[0] = sio_data->address[0];
@@ -1089,7 +1091,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
 
        err = pc87427_request_regions(pdev, res_count);
        if (err)
-               goto exit_kfree;
+               return err;
 
        mutex_init(&data->lock);
        data->name = "pc87427";
@@ -1099,7 +1101,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
        /* Register sysfs hooks */
        err = device_create_file(&pdev->dev, &dev_attr_name);
        if (err)
-               goto exit_release_region;
+               return err;
        for (i = 0; i < 8; i++) {
                if (!(data->fan_enabled & (1 << i)))
                        continue;
@@ -1136,28 +1138,15 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
 
 exit_remove_files:
        pc87427_remove_files(&pdev->dev);
-exit_release_region:
-       pc87427_release_regions(pdev, res_count);
-exit_kfree:
-       platform_set_drvdata(pdev, NULL);
-       kfree(data);
-exit:
        return err;
 }
 
 static int __devexit pc87427_remove(struct platform_device *pdev)
 {
        struct pc87427_data *data = platform_get_drvdata(pdev);
-       int res_count;
-
-       res_count = (data->address[0] != 0) + (data->address[1] != 0);
 
        hwmon_device_unregister(data->hwmon_dev);
        pc87427_remove_files(&pdev->dev);
-       platform_set_drvdata(pdev, NULL);
-       kfree(data);
-
-       pc87427_release_regions(pdev, res_count);
 
        return 0;
 }