diff options
Diffstat (limited to 'drivers/hwmon/gpio-fan.c')
-rw-r--r-- | drivers/hwmon/gpio-fan.c | 77 |
1 files changed, 26 insertions, 51 deletions
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 2ce8c44a0e0..2f4b01bda87 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -41,7 +41,7 @@ struct gpio_fan_data { int num_speed; struct gpio_fan_speed *speed; int speed_index; -#ifdef CONFIG_PM +#ifdef CONFIG_PM_SLEEP int resume_speed; #endif bool pwm_enable; @@ -95,17 +95,17 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data, fan_data->alarm = alarm; - err = gpio_request(alarm->gpio, "GPIO fan alarm"); + err = devm_gpio_request(&pdev->dev, alarm->gpio, "GPIO fan alarm"); if (err) return err; err = gpio_direction_input(alarm->gpio); if (err) - goto err_free_gpio; + return err; err = device_create_file(&pdev->dev, &dev_attr_fan1_alarm); if (err) - goto err_free_gpio; + return err; /* * If the alarm GPIO don't support interrupts, just leave @@ -117,8 +117,8 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data, INIT_WORK(&fan_data->alarm_work, fan_alarm_notify); irq_set_irq_type(alarm_irq, IRQ_TYPE_EDGE_BOTH); - err = request_irq(alarm_irq, fan_alarm_irq_handler, IRQF_SHARED, - "GPIO fan alarm", fan_data); + err = devm_request_irq(&pdev->dev, alarm_irq, fan_alarm_irq_handler, + IRQF_SHARED, "GPIO fan alarm", fan_data); if (err) goto err_free_sysfs; @@ -126,21 +126,14 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data, err_free_sysfs: device_remove_file(&pdev->dev, &dev_attr_fan1_alarm); -err_free_gpio: - gpio_free(alarm->gpio); - return err; } static void fan_alarm_free(struct gpio_fan_data *fan_data) { struct platform_device *pdev = fan_data->pdev; - int alarm_irq = gpio_to_irq(fan_data->alarm->gpio); - if (alarm_irq >= 0) - free_irq(alarm_irq, fan_data); device_remove_file(&pdev->dev, &dev_attr_fan1_alarm); - gpio_free(fan_data->alarm->gpio); } /* @@ -365,15 +358,14 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data, int i, err; for (i = 0; i < num_ctrl; i++) { - err = gpio_request(ctrl[i], "GPIO fan control"); + err = devm_gpio_request(&pdev->dev, ctrl[i], + "GPIO fan control"); if (err) - goto err_free_gpio; + return err; err = gpio_direction_output(ctrl[i], gpio_get_value(ctrl[i])); - if (err) { - gpio_free(ctrl[i]); - goto err_free_gpio; - } + if (err) + return err; } fan_data->num_ctrl = num_ctrl; @@ -382,32 +374,18 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data, fan_data->speed = pdata->speed; fan_data->pwm_enable = true; /* Enable manual fan speed control. */ fan_data->speed_index = get_fan_speed_index(fan_data); - if (fan_data->speed_index < 0) { - err = -ENODEV; - goto err_free_gpio; - } + if (fan_data->speed_index < 0) + return -ENODEV; err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_ctrl_group); - if (err) - goto err_free_gpio; - - return 0; - -err_free_gpio: - for (i = i - 1; i >= 0; i--) - gpio_free(ctrl[i]); - return err; } static void fan_ctrl_free(struct gpio_fan_data *fan_data) { struct platform_device *pdev = fan_data->pdev; - int i; sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_ctrl_group); - for (i = 0; i < fan_data->num_ctrl; i++) - gpio_free(fan_data->ctrl[i]); } /* @@ -431,7 +409,8 @@ static int __devinit gpio_fan_probe(struct platform_device *pdev) if (!pdata) return -EINVAL; - fan_data = kzalloc(sizeof(struct gpio_fan_data), GFP_KERNEL); + fan_data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_fan_data), + GFP_KERNEL); if (!fan_data) return -ENOMEM; @@ -443,7 +422,7 @@ static int __devinit gpio_fan_probe(struct platform_device *pdev) if (pdata->alarm) { err = fan_alarm_init(fan_data, pdata->alarm); if (err) - goto err_free_data; + return err; } /* Configure control GPIOs if available. */ @@ -480,10 +459,6 @@ err_free_ctrl: err_free_alarm: if (fan_data->alarm) fan_alarm_free(fan_data); -err_free_data: - platform_set_drvdata(pdev, NULL); - kfree(fan_data); - return err; } @@ -497,15 +472,14 @@ static int __devexit gpio_fan_remove(struct platform_device *pdev) fan_alarm_free(fan_data); if (fan_data->ctrl) fan_ctrl_free(fan_data); - kfree(fan_data); return 0; } -#ifdef CONFIG_PM -static int gpio_fan_suspend(struct platform_device *pdev, pm_message_t state) +#ifdef CONFIG_PM_SLEEP +static int gpio_fan_suspend(struct device *dev) { - struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); + struct gpio_fan_data *fan_data = dev_get_drvdata(dev); if (fan_data->ctrl) { fan_data->resume_speed = fan_data->speed_index; @@ -515,27 +489,28 @@ static int gpio_fan_suspend(struct platform_device *pdev, pm_message_t state) return 0; } -static int gpio_fan_resume(struct platform_device *pdev) +static int gpio_fan_resume(struct device *dev) { - struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); + struct gpio_fan_data *fan_data = dev_get_drvdata(dev); if (fan_data->ctrl) set_fan_speed(fan_data, fan_data->resume_speed); return 0; } + +static SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume); +#define GPIO_FAN_PM &gpio_fan_pm #else -#define gpio_fan_suspend NULL -#define gpio_fan_resume NULL +#define GPIO_FAN_PM NULL #endif static struct platform_driver gpio_fan_driver = { .probe = gpio_fan_probe, .remove = __devexit_p(gpio_fan_remove), - .suspend = gpio_fan_suspend, - .resume = gpio_fan_resume, .driver = { .name = "gpio-fan", + .pm = GPIO_FAN_PM, }, }; |