summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/gpio-fan.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-09-25 19:09:09 -0400
committerGuenter Roeck <linux@roeck-us.net>2017-10-29 21:36:03 -0400
commitc9933cb16f166de57b0b8bce170c1b9476b89836 (patch)
tree9d7edd1ad3e636543c84be58a16d5055b707dd82 /drivers/hwmon/gpio-fan.c
parentb5482f7e6cc5639440bfa0b9bb4a3a9732883f53 (diff)
hwmon: (gpio-fan) Get rid of the gpio alarm struct
There is no point in storing the GPIO alarm settings in their own struct so merge this into the main state container. Convert the variables from "unsigned" to "unsigned int" to make checkpatch happy. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/gpio-fan.c')
-rw-r--r--drivers/hwmon/gpio-fan.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 000c8d2e0987..568ce4b25a9e 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -35,11 +35,6 @@
35#include <linux/of_gpio.h> 35#include <linux/of_gpio.h>
36#include <linux/thermal.h> 36#include <linux/thermal.h>
37 37
38struct gpio_fan_alarm {
39 unsigned int gpio;
40 unsigned int active_low;
41};
42
43struct gpio_fan_speed { 38struct gpio_fan_speed {
44 int rpm; 39 int rpm;
45 int ctrl_val; 40 int ctrl_val;
@@ -60,7 +55,8 @@ struct gpio_fan_data {
60 int resume_speed; 55 int resume_speed;
61#endif 56#endif
62 bool pwm_enable; 57 bool pwm_enable;
63 struct gpio_fan_alarm *alarm; 58 unsigned int alarm_gpio;
59 unsigned int alarm_gpio_active_low;
64 struct work_struct alarm_work; 60 struct work_struct alarm_work;
65}; 61};
66 62
@@ -90,10 +86,9 @@ static ssize_t fan1_alarm_show(struct device *dev,
90 struct device_attribute *attr, char *buf) 86 struct device_attribute *attr, char *buf)
91{ 87{
92 struct gpio_fan_data *fan_data = dev_get_drvdata(dev); 88 struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
93 struct gpio_fan_alarm *alarm = fan_data->alarm; 89 int value = gpio_get_value_cansleep(fan_data->alarm_gpio);
94 int value = gpio_get_value_cansleep(alarm->gpio);
95 90
96 if (alarm->active_low) 91 if (fan_data->alarm_gpio_active_low)
97 value = !value; 92 value = !value;
98 93
99 return sprintf(buf, "%d\n", value); 94 return sprintf(buf, "%d\n", value);
@@ -106,13 +101,12 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data)
106 int err; 101 int err;
107 int alarm_irq; 102 int alarm_irq;
108 struct device *dev = fan_data->dev; 103 struct device *dev = fan_data->dev;
109 struct gpio_fan_alarm *alarm = fan_data->alarm;
110 104
111 err = devm_gpio_request(dev, alarm->gpio, "GPIO fan alarm"); 105 err = devm_gpio_request(dev, fan_data->alarm_gpio, "GPIO fan alarm");
112 if (err) 106 if (err)
113 return err; 107 return err;
114 108
115 err = gpio_direction_input(alarm->gpio); 109 err = gpio_direction_input(fan_data->alarm_gpio);
116 if (err) 110 if (err)
117 return err; 111 return err;
118 112
@@ -120,7 +114,7 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data)
120 * If the alarm GPIO don't support interrupts, just leave 114 * If the alarm GPIO don't support interrupts, just leave
121 * without initializing the fail notification support. 115 * without initializing the fail notification support.
122 */ 116 */
123 alarm_irq = gpio_to_irq(alarm->gpio); 117 alarm_irq = gpio_to_irq(fan_data->alarm_gpio);
124 if (alarm_irq < 0) 118 if (alarm_irq < 0)
125 return 0; 119 return 0;
126 120
@@ -335,7 +329,7 @@ static umode_t gpio_fan_is_visible(struct kobject *kobj,
335 struct device *dev = container_of(kobj, struct device, kobj); 329 struct device *dev = container_of(kobj, struct device, kobj);
336 struct gpio_fan_data *data = dev_get_drvdata(dev); 330 struct gpio_fan_data *data = dev_get_drvdata(dev);
337 331
338 if (index == 0 && !data->alarm) 332 if (index == 0 && !data->alarm_gpio)
339 return 0; 333 return 0;
340 if (index > 0 && !data->ctrl) 334 if (index > 0 && !data->ctrl)
341 return 0; 335 return 0;
@@ -450,28 +444,20 @@ static int gpio_fan_get_of_data(struct gpio_fan_data *fan_data)
450 444
451 /* Alarm GPIO if one exists */ 445 /* Alarm GPIO if one exists */
452 if (of_gpio_named_count(np, "alarm-gpios") > 0) { 446 if (of_gpio_named_count(np, "alarm-gpios") > 0) {
453 struct gpio_fan_alarm *alarm;
454 int val; 447 int val;
455 enum of_gpio_flags flags; 448 enum of_gpio_flags flags;
456 449
457 alarm = devm_kzalloc(dev, sizeof(struct gpio_fan_alarm),
458 GFP_KERNEL);
459 if (!alarm)
460 return -ENOMEM;
461
462 val = of_get_named_gpio_flags(np, "alarm-gpios", 0, &flags); 450 val = of_get_named_gpio_flags(np, "alarm-gpios", 0, &flags);
463 if (val < 0) 451 if (val < 0)
464 return val; 452 return val;
465 alarm->gpio = val; 453 fan_data->alarm_gpio = val;
466 alarm->active_low = flags & OF_GPIO_ACTIVE_LOW; 454 fan_data->alarm_gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;
467
468 fan_data->alarm = alarm;
469 } 455 }
470 456
471 /* Fill GPIO pin array */ 457 /* Fill GPIO pin array */
472 fan_data->num_ctrl = of_gpio_count(np); 458 fan_data->num_ctrl = of_gpio_count(np);
473 if (fan_data->num_ctrl <= 0) { 459 if (fan_data->num_ctrl <= 0) {
474 if (fan_data->alarm) 460 if (fan_data->alarm_gpio)
475 return 0; 461 return 0;
476 dev_err(dev, "DT properties empty / missing"); 462 dev_err(dev, "DT properties empty / missing");
477 return -ENODEV; 463 return -ENODEV;
@@ -556,7 +542,7 @@ static int gpio_fan_probe(struct platform_device *pdev)
556 mutex_init(&fan_data->lock); 542 mutex_init(&fan_data->lock);
557 543
558 /* Configure alarm GPIO if available. */ 544 /* Configure alarm GPIO if available. */
559 if (fan_data->alarm) { 545 if (fan_data->alarm_gpio) {
560 err = fan_alarm_init(fan_data); 546 err = fan_alarm_init(fan_data);
561 if (err) 547 if (err)
562 return err; 548 return err;