Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * gpio-fan.c - Hwmon driver for fans connected to GPIO lines. |
| 3 | * |
| 4 | * Copyright (C) 2010 LaCie |
| 5 | * |
| 6 | * Author: Simon Guinot <sguinot@lacie.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/irq.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/err.h> |
| 30 | #include <linux/mutex.h> |
| 31 | #include <linux/hwmon.h> |
| 32 | #include <linux/gpio.h> |
Sachin Kamat | c50588a | 2013-09-27 16:56:00 +0530 | [diff] [blame] | 33 | #include <linux/of.h> |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 34 | #include <linux/of_platform.h> |
| 35 | #include <linux/of_gpio.h> |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 36 | #include <linux/thermal.h> |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 37 | |
Linus Walleij | ef7a612 | 2017-09-26 01:09:05 +0200 | [diff] [blame] | 38 | struct gpio_fan_alarm { |
| 39 | unsigned int gpio; |
| 40 | unsigned int active_low; |
| 41 | }; |
| 42 | |
| 43 | struct gpio_fan_speed { |
| 44 | int rpm; |
| 45 | int ctrl_val; |
| 46 | }; |
| 47 | |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 48 | struct gpio_fan_data { |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 49 | struct device *dev; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 50 | struct device *hwmon_dev; |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 51 | /* Cooling device if any */ |
| 52 | struct thermal_cooling_device *cdev; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 53 | struct mutex lock; /* lock GPIOs operations. */ |
| 54 | int num_ctrl; |
| 55 | unsigned *ctrl; |
| 56 | int num_speed; |
| 57 | struct gpio_fan_speed *speed; |
| 58 | int speed_index; |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_PM_SLEEP |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 60 | int resume_speed; |
| 61 | #endif |
| 62 | bool pwm_enable; |
| 63 | struct gpio_fan_alarm *alarm; |
| 64 | struct work_struct alarm_work; |
| 65 | }; |
| 66 | |
| 67 | /* |
| 68 | * Alarm GPIO. |
| 69 | */ |
| 70 | |
| 71 | static void fan_alarm_notify(struct work_struct *ws) |
| 72 | { |
| 73 | struct gpio_fan_data *fan_data = |
| 74 | container_of(ws, struct gpio_fan_data, alarm_work); |
| 75 | |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 76 | sysfs_notify(&fan_data->dev->kobj, NULL, "fan1_alarm"); |
| 77 | kobject_uevent(&fan_data->dev->kobj, KOBJ_CHANGE); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static irqreturn_t fan_alarm_irq_handler(int irq, void *dev_id) |
| 81 | { |
| 82 | struct gpio_fan_data *fan_data = dev_id; |
| 83 | |
| 84 | schedule_work(&fan_data->alarm_work); |
| 85 | |
| 86 | return IRQ_NONE; |
| 87 | } |
| 88 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 89 | static ssize_t fan1_alarm_show(struct device *dev, |
| 90 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 91 | { |
| 92 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 93 | struct gpio_fan_alarm *alarm = fan_data->alarm; |
Nishanth Menon | 52a95c1 | 2014-12-04 10:58:47 -0600 | [diff] [blame] | 94 | int value = gpio_get_value_cansleep(alarm->gpio); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 95 | |
| 96 | if (alarm->active_low) |
| 97 | value = !value; |
| 98 | |
| 99 | return sprintf(buf, "%d\n", value); |
| 100 | } |
| 101 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 102 | static DEVICE_ATTR_RO(fan1_alarm); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 103 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 104 | static int fan_alarm_init(struct gpio_fan_data *fan_data) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 105 | { |
| 106 | int err; |
| 107 | int alarm_irq; |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 108 | struct device *dev = fan_data->dev; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 109 | struct gpio_fan_alarm *alarm = fan_data->alarm; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 110 | |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 111 | err = devm_gpio_request(dev, alarm->gpio, "GPIO fan alarm"); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 112 | if (err) |
| 113 | return err; |
| 114 | |
| 115 | err = gpio_direction_input(alarm->gpio); |
| 116 | if (err) |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 117 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 118 | |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 119 | /* |
| 120 | * If the alarm GPIO don't support interrupts, just leave |
| 121 | * without initializing the fail notification support. |
| 122 | */ |
| 123 | alarm_irq = gpio_to_irq(alarm->gpio); |
| 124 | if (alarm_irq < 0) |
| 125 | return 0; |
| 126 | |
| 127 | INIT_WORK(&fan_data->alarm_work, fan_alarm_notify); |
Thomas Gleixner | dced35a | 2011-03-28 17:49:12 +0200 | [diff] [blame] | 128 | irq_set_irq_type(alarm_irq, IRQ_TYPE_EDGE_BOTH); |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 129 | err = devm_request_irq(dev, alarm_irq, fan_alarm_irq_handler, |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 130 | IRQF_SHARED, "GPIO fan alarm", fan_data); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 131 | return err; |
| 132 | } |
| 133 | |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 134 | /* |
| 135 | * Control GPIOs. |
| 136 | */ |
| 137 | |
| 138 | /* Must be called with fan_data->lock held, except during initialization. */ |
| 139 | static void __set_fan_ctrl(struct gpio_fan_data *fan_data, int ctrl_val) |
| 140 | { |
| 141 | int i; |
| 142 | |
| 143 | for (i = 0; i < fan_data->num_ctrl; i++) |
Nishanth Menon | 52a95c1 | 2014-12-04 10:58:47 -0600 | [diff] [blame] | 144 | gpio_set_value_cansleep(fan_data->ctrl[i], (ctrl_val >> i) & 1); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static int __get_fan_ctrl(struct gpio_fan_data *fan_data) |
| 148 | { |
| 149 | int i; |
| 150 | int ctrl_val = 0; |
| 151 | |
| 152 | for (i = 0; i < fan_data->num_ctrl; i++) { |
| 153 | int value; |
| 154 | |
Nishanth Menon | 52a95c1 | 2014-12-04 10:58:47 -0600 | [diff] [blame] | 155 | value = gpio_get_value_cansleep(fan_data->ctrl[i]); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 156 | ctrl_val |= (value << i); |
| 157 | } |
| 158 | return ctrl_val; |
| 159 | } |
| 160 | |
| 161 | /* Must be called with fan_data->lock held, except during initialization. */ |
| 162 | static void set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) |
| 163 | { |
| 164 | if (fan_data->speed_index == speed_index) |
| 165 | return; |
| 166 | |
| 167 | __set_fan_ctrl(fan_data, fan_data->speed[speed_index].ctrl_val); |
| 168 | fan_data->speed_index = speed_index; |
| 169 | } |
| 170 | |
| 171 | static int get_fan_speed_index(struct gpio_fan_data *fan_data) |
| 172 | { |
| 173 | int ctrl_val = __get_fan_ctrl(fan_data); |
| 174 | int i; |
| 175 | |
| 176 | for (i = 0; i < fan_data->num_speed; i++) |
| 177 | if (fan_data->speed[i].ctrl_val == ctrl_val) |
| 178 | return i; |
| 179 | |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 180 | dev_warn(fan_data->dev, |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 181 | "missing speed array entry for GPIO value 0x%x\n", ctrl_val); |
| 182 | |
Guenter Roeck | c52ae3d | 2013-09-13 10:42:39 -0700 | [diff] [blame] | 183 | return -ENODEV; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Axel Lin | 2565fb0 | 2014-08-02 13:36:38 +0800 | [diff] [blame] | 186 | static int rpm_to_speed_index(struct gpio_fan_data *fan_data, unsigned long rpm) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 187 | { |
| 188 | struct gpio_fan_speed *speed = fan_data->speed; |
| 189 | int i; |
| 190 | |
| 191 | for (i = 0; i < fan_data->num_speed; i++) |
| 192 | if (speed[i].rpm >= rpm) |
| 193 | return i; |
| 194 | |
| 195 | return fan_data->num_speed - 1; |
| 196 | } |
| 197 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 198 | static ssize_t pwm1_show(struct device *dev, struct device_attribute *attr, |
| 199 | char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 200 | { |
| 201 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 202 | u8 pwm = fan_data->speed_index * 255 / (fan_data->num_speed - 1); |
| 203 | |
| 204 | return sprintf(buf, "%d\n", pwm); |
| 205 | } |
| 206 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 207 | static ssize_t pwm1_store(struct device *dev, struct device_attribute *attr, |
| 208 | const char *buf, size_t count) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 209 | { |
| 210 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 211 | unsigned long pwm; |
| 212 | int speed_index; |
| 213 | int ret = count; |
| 214 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 215 | if (kstrtoul(buf, 10, &pwm) || pwm > 255) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | |
| 218 | mutex_lock(&fan_data->lock); |
| 219 | |
| 220 | if (!fan_data->pwm_enable) { |
| 221 | ret = -EPERM; |
| 222 | goto exit_unlock; |
| 223 | } |
| 224 | |
| 225 | speed_index = DIV_ROUND_UP(pwm * (fan_data->num_speed - 1), 255); |
| 226 | set_fan_speed(fan_data, speed_index); |
| 227 | |
| 228 | exit_unlock: |
| 229 | mutex_unlock(&fan_data->lock); |
| 230 | |
| 231 | return ret; |
| 232 | } |
| 233 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 234 | static ssize_t pwm1_enable_show(struct device *dev, |
| 235 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 236 | { |
| 237 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 238 | |
| 239 | return sprintf(buf, "%d\n", fan_data->pwm_enable); |
| 240 | } |
| 241 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 242 | static ssize_t pwm1_enable_store(struct device *dev, |
| 243 | struct device_attribute *attr, |
| 244 | const char *buf, size_t count) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 245 | { |
| 246 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 247 | unsigned long val; |
| 248 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 249 | if (kstrtoul(buf, 10, &val) || val > 1) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 250 | return -EINVAL; |
| 251 | |
| 252 | if (fan_data->pwm_enable == val) |
| 253 | return count; |
| 254 | |
| 255 | mutex_lock(&fan_data->lock); |
| 256 | |
| 257 | fan_data->pwm_enable = val; |
| 258 | |
| 259 | /* Disable manual control mode: set fan at full speed. */ |
| 260 | if (val == 0) |
| 261 | set_fan_speed(fan_data, fan_data->num_speed - 1); |
| 262 | |
| 263 | mutex_unlock(&fan_data->lock); |
| 264 | |
| 265 | return count; |
| 266 | } |
| 267 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 268 | static ssize_t pwm1_mode_show(struct device *dev, |
| 269 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 270 | { |
| 271 | return sprintf(buf, "0\n"); |
| 272 | } |
| 273 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 274 | static ssize_t fan1_min_show(struct device *dev, |
| 275 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 276 | { |
| 277 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 278 | |
| 279 | return sprintf(buf, "%d\n", fan_data->speed[0].rpm); |
| 280 | } |
| 281 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 282 | static ssize_t fan1_max_show(struct device *dev, |
| 283 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 284 | { |
| 285 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 286 | |
| 287 | return sprintf(buf, "%d\n", |
| 288 | fan_data->speed[fan_data->num_speed - 1].rpm); |
| 289 | } |
| 290 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 291 | static ssize_t fan1_input_show(struct device *dev, |
| 292 | struct device_attribute *attr, char *buf) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 293 | { |
| 294 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 295 | |
| 296 | return sprintf(buf, "%d\n", fan_data->speed[fan_data->speed_index].rpm); |
| 297 | } |
| 298 | |
| 299 | static ssize_t set_rpm(struct device *dev, struct device_attribute *attr, |
| 300 | const char *buf, size_t count) |
| 301 | { |
| 302 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
| 303 | unsigned long rpm; |
| 304 | int ret = count; |
| 305 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 306 | if (kstrtoul(buf, 10, &rpm)) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 307 | return -EINVAL; |
| 308 | |
| 309 | mutex_lock(&fan_data->lock); |
| 310 | |
| 311 | if (!fan_data->pwm_enable) { |
| 312 | ret = -EPERM; |
| 313 | goto exit_unlock; |
| 314 | } |
| 315 | |
| 316 | set_fan_speed(fan_data, rpm_to_speed_index(fan_data, rpm)); |
| 317 | |
| 318 | exit_unlock: |
| 319 | mutex_unlock(&fan_data->lock); |
| 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
Julia Lawall | c490c63 | 2016-12-22 13:04:44 +0100 | [diff] [blame] | 324 | static DEVICE_ATTR_RW(pwm1); |
| 325 | static DEVICE_ATTR_RW(pwm1_enable); |
| 326 | static DEVICE_ATTR_RO(pwm1_mode); |
| 327 | static DEVICE_ATTR_RO(fan1_min); |
| 328 | static DEVICE_ATTR_RO(fan1_max); |
| 329 | static DEVICE_ATTR_RO(fan1_input); |
| 330 | static DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, fan1_input_show, set_rpm); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 331 | |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 332 | static umode_t gpio_fan_is_visible(struct kobject *kobj, |
| 333 | struct attribute *attr, int index) |
| 334 | { |
| 335 | struct device *dev = container_of(kobj, struct device, kobj); |
| 336 | struct gpio_fan_data *data = dev_get_drvdata(dev); |
| 337 | |
Guenter Roeck | 7258a12 | 2013-07-06 09:46:14 -0700 | [diff] [blame] | 338 | if (index == 0 && !data->alarm) |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 339 | return 0; |
Guenter Roeck | 7258a12 | 2013-07-06 09:46:14 -0700 | [diff] [blame] | 340 | if (index > 0 && !data->ctrl) |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 341 | return 0; |
| 342 | |
| 343 | return attr->mode; |
| 344 | } |
| 345 | |
| 346 | static struct attribute *gpio_fan_attributes[] = { |
Guenter Roeck | 7258a12 | 2013-07-06 09:46:14 -0700 | [diff] [blame] | 347 | &dev_attr_fan1_alarm.attr, /* 0 */ |
| 348 | &dev_attr_pwm1.attr, /* 1 */ |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 349 | &dev_attr_pwm1_enable.attr, |
| 350 | &dev_attr_pwm1_mode.attr, |
| 351 | &dev_attr_fan1_input.attr, |
| 352 | &dev_attr_fan1_target.attr, |
| 353 | &dev_attr_fan1_min.attr, |
| 354 | &dev_attr_fan1_max.attr, |
| 355 | NULL |
| 356 | }; |
| 357 | |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 358 | static const struct attribute_group gpio_fan_group = { |
| 359 | .attrs = gpio_fan_attributes, |
| 360 | .is_visible = gpio_fan_is_visible, |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 361 | }; |
| 362 | |
Guenter Roeck | 7258a12 | 2013-07-06 09:46:14 -0700 | [diff] [blame] | 363 | static const struct attribute_group *gpio_fan_groups[] = { |
| 364 | &gpio_fan_group, |
| 365 | NULL |
| 366 | }; |
| 367 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 368 | static int fan_ctrl_init(struct gpio_fan_data *fan_data) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 369 | { |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 370 | struct device *dev = fan_data->dev; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 371 | int num_ctrl = fan_data->num_ctrl; |
| 372 | unsigned int *ctrl = fan_data->ctrl; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 373 | int i, err; |
| 374 | |
| 375 | for (i = 0; i < num_ctrl; i++) { |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 376 | err = devm_gpio_request(dev, ctrl[i], |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 377 | "GPIO fan control"); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 378 | if (err) |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 379 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 380 | |
Nishanth Menon | 52a95c1 | 2014-12-04 10:58:47 -0600 | [diff] [blame] | 381 | err = gpio_direction_output(ctrl[i], |
| 382 | gpio_get_value_cansleep(ctrl[i])); |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 383 | if (err) |
| 384 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 387 | fan_data->pwm_enable = true; /* Enable manual fan speed control. */ |
| 388 | fan_data->speed_index = get_fan_speed_index(fan_data); |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 389 | if (fan_data->speed_index < 0) |
Guenter Roeck | c52ae3d | 2013-09-13 10:42:39 -0700 | [diff] [blame] | 390 | return fan_data->speed_index; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 391 | |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 392 | return 0; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 395 | static int gpio_fan_get_max_state(struct thermal_cooling_device *cdev, |
| 396 | unsigned long *state) |
| 397 | { |
| 398 | struct gpio_fan_data *fan_data = cdev->devdata; |
| 399 | |
| 400 | if (!fan_data) |
| 401 | return -EINVAL; |
| 402 | |
| 403 | *state = fan_data->num_speed - 1; |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int gpio_fan_get_cur_state(struct thermal_cooling_device *cdev, |
| 408 | unsigned long *state) |
| 409 | { |
| 410 | struct gpio_fan_data *fan_data = cdev->devdata; |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 411 | |
| 412 | if (!fan_data) |
| 413 | return -EINVAL; |
| 414 | |
Nishanth Menon | 000e0949 | 2016-02-19 18:09:51 -0600 | [diff] [blame] | 415 | *state = fan_data->speed_index; |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static int gpio_fan_set_cur_state(struct thermal_cooling_device *cdev, |
| 420 | unsigned long state) |
| 421 | { |
| 422 | struct gpio_fan_data *fan_data = cdev->devdata; |
| 423 | |
| 424 | if (!fan_data) |
| 425 | return -EINVAL; |
| 426 | |
| 427 | set_fan_speed(fan_data, state); |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static const struct thermal_cooling_device_ops gpio_fan_cool_ops = { |
| 432 | .get_max_state = gpio_fan_get_max_state, |
| 433 | .get_cur_state = gpio_fan_get_cur_state, |
| 434 | .set_cur_state = gpio_fan_set_cur_state, |
| 435 | }; |
| 436 | |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 437 | /* |
| 438 | * Translate OpenFirmware node properties into platform_data |
| 439 | */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 440 | static int gpio_fan_get_of_data(struct gpio_fan_data *fan_data) |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 441 | { |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 442 | struct gpio_fan_speed *speed; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 443 | struct device *dev = fan_data->dev; |
| 444 | struct device_node *np = dev->of_node; |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 445 | unsigned *ctrl; |
| 446 | unsigned i; |
| 447 | u32 u; |
| 448 | struct property *prop; |
| 449 | const __be32 *p; |
| 450 | |
Simon Guinot | 73ef85f | 2015-02-25 18:58:19 +0100 | [diff] [blame] | 451 | /* Alarm GPIO if one exists */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 452 | if (of_gpio_named_count(np, "alarm-gpios") > 0) { |
Simon Guinot | 73ef85f | 2015-02-25 18:58:19 +0100 | [diff] [blame] | 453 | struct gpio_fan_alarm *alarm; |
| 454 | int val; |
| 455 | enum of_gpio_flags flags; |
| 456 | |
| 457 | alarm = devm_kzalloc(dev, sizeof(struct gpio_fan_alarm), |
| 458 | GFP_KERNEL); |
| 459 | if (!alarm) |
| 460 | return -ENOMEM; |
| 461 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 462 | val = of_get_named_gpio_flags(np, "alarm-gpios", 0, &flags); |
Simon Guinot | 73ef85f | 2015-02-25 18:58:19 +0100 | [diff] [blame] | 463 | if (val < 0) |
| 464 | return val; |
| 465 | alarm->gpio = val; |
| 466 | alarm->active_low = flags & OF_GPIO_ACTIVE_LOW; |
| 467 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 468 | fan_data->alarm = alarm; |
Simon Guinot | 73ef85f | 2015-02-25 18:58:19 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 471 | /* Fill GPIO pin array */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 472 | fan_data->num_ctrl = of_gpio_count(np); |
| 473 | if (fan_data->num_ctrl <= 0) { |
| 474 | if (fan_data->alarm) |
Simon Guinot | 73ef85f | 2015-02-25 18:58:19 +0100 | [diff] [blame] | 475 | return 0; |
| 476 | dev_err(dev, "DT properties empty / missing"); |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 477 | return -ENODEV; |
| 478 | } |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 479 | ctrl = devm_kzalloc(dev, fan_data->num_ctrl * sizeof(unsigned int), |
| 480 | GFP_KERNEL); |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 481 | if (!ctrl) |
| 482 | return -ENOMEM; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 483 | for (i = 0; i < fan_data->num_ctrl; i++) { |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 484 | int val; |
| 485 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 486 | val = of_get_gpio(np, i); |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 487 | if (val < 0) |
| 488 | return val; |
| 489 | ctrl[i] = val; |
| 490 | } |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 491 | fan_data->ctrl = ctrl; |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 492 | |
| 493 | /* Get number of RPM/ctrl_val pairs in speed map */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 494 | prop = of_find_property(np, "gpio-fan,speed-map", &i); |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 495 | if (!prop) { |
| 496 | dev_err(dev, "gpio-fan,speed-map DT property missing"); |
| 497 | return -ENODEV; |
| 498 | } |
| 499 | i = i / sizeof(u32); |
| 500 | if (i == 0 || i & 1) { |
| 501 | dev_err(dev, "gpio-fan,speed-map contains zero/odd number of entries"); |
| 502 | return -ENODEV; |
| 503 | } |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 504 | fan_data->num_speed = i / 2; |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 505 | |
| 506 | /* |
| 507 | * Populate speed map |
| 508 | * Speed map is in the form <RPM ctrl_val RPM ctrl_val ...> |
| 509 | * this needs splitting into pairs to create gpio_fan_speed structs |
| 510 | */ |
| 511 | speed = devm_kzalloc(dev, |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 512 | fan_data->num_speed * sizeof(struct gpio_fan_speed), |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 513 | GFP_KERNEL); |
| 514 | if (!speed) |
| 515 | return -ENOMEM; |
| 516 | p = NULL; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 517 | for (i = 0; i < fan_data->num_speed; i++) { |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 518 | p = of_prop_next_u32(prop, p, &u); |
| 519 | if (!p) |
| 520 | return -ENODEV; |
| 521 | speed[i].rpm = u; |
| 522 | p = of_prop_next_u32(prop, p, &u); |
| 523 | if (!p) |
| 524 | return -ENODEV; |
| 525 | speed[i].ctrl_val = u; |
| 526 | } |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 527 | fan_data->speed = speed; |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 528 | |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
Jingoo Han | 6de709c | 2014-05-07 17:27:54 +0900 | [diff] [blame] | 532 | static const struct of_device_id of_gpio_fan_match[] = { |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 533 | { .compatible = "gpio-fan", }, |
| 534 | {}, |
| 535 | }; |
Luis de Bethencourt | fe51528 | 2015-09-17 18:09:28 +0200 | [diff] [blame] | 536 | MODULE_DEVICE_TABLE(of, of_gpio_fan_match); |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 537 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 538 | static int gpio_fan_probe(struct platform_device *pdev) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 539 | { |
| 540 | int err; |
| 541 | struct gpio_fan_data *fan_data; |
Linus Walleij | f9013c1 | 2017-09-26 01:09:04 +0200 | [diff] [blame] | 542 | struct device *dev = &pdev->dev; |
| 543 | struct device_node *np = dev->of_node; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 544 | |
Linus Walleij | f9013c1 | 2017-09-26 01:09:04 +0200 | [diff] [blame] | 545 | fan_data = devm_kzalloc(dev, sizeof(struct gpio_fan_data), |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 546 | GFP_KERNEL); |
| 547 | if (!fan_data) |
| 548 | return -ENOMEM; |
| 549 | |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 550 | err = gpio_fan_get_of_data(fan_data); |
Linus Walleij | a9b4c8a | 2017-09-26 01:09:07 +0200 | [diff] [blame] | 551 | if (err) |
| 552 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 553 | |
Linus Walleij | 8c0eb9b | 2017-09-26 01:09:06 +0200 | [diff] [blame] | 554 | fan_data->dev = dev; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 555 | platform_set_drvdata(pdev, fan_data); |
| 556 | mutex_init(&fan_data->lock); |
| 557 | |
| 558 | /* Configure alarm GPIO if available. */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 559 | if (fan_data->alarm) { |
| 560 | err = fan_alarm_init(fan_data); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 561 | if (err) |
Guenter Roeck | d00985f | 2012-06-02 09:58:07 -0700 | [diff] [blame] | 562 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /* Configure control GPIOs if available. */ |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 566 | if (fan_data->ctrl && fan_data->num_ctrl > 0) { |
| 567 | if (!fan_data->speed || fan_data->num_speed <= 1) |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 568 | return -EINVAL; |
Linus Walleij | b5482f7 | 2017-09-26 01:09:08 +0200 | [diff] [blame^] | 569 | err = fan_ctrl_init(fan_data); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 570 | if (err) |
Guenter Roeck | c81cc5a | 2013-03-30 09:09:39 -0700 | [diff] [blame] | 571 | return err; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 574 | /* Make this driver part of hwmon class. */ |
Axel Lin | 49153b0 | 2014-06-14 14:50:50 +0800 | [diff] [blame] | 575 | fan_data->hwmon_dev = |
Linus Walleij | f9013c1 | 2017-09-26 01:09:04 +0200 | [diff] [blame] | 576 | devm_hwmon_device_register_with_groups(dev, |
Axel Lin | 49153b0 | 2014-06-14 14:50:50 +0800 | [diff] [blame] | 577 | "gpio_fan", fan_data, |
| 578 | gpio_fan_groups); |
Guenter Roeck | 7258a12 | 2013-07-06 09:46:14 -0700 | [diff] [blame] | 579 | if (IS_ERR(fan_data->hwmon_dev)) |
| 580 | return PTR_ERR(fan_data->hwmon_dev); |
Linus Walleij | a9b4c8a | 2017-09-26 01:09:07 +0200 | [diff] [blame] | 581 | |
Nishanth Menon | e76ea26 | 2015-04-08 18:23:52 -0500 | [diff] [blame] | 582 | /* Optional cooling device register for Device tree platforms */ |
Linus Walleij | f9013c1 | 2017-09-26 01:09:04 +0200 | [diff] [blame] | 583 | fan_data->cdev = thermal_of_cooling_device_register(np, |
Nishanth Menon | e76ea26 | 2015-04-08 18:23:52 -0500 | [diff] [blame] | 584 | "gpio-fan", |
| 585 | fan_data, |
| 586 | &gpio_fan_cool_ops); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 587 | |
Linus Walleij | f9013c1 | 2017-09-26 01:09:04 +0200 | [diff] [blame] | 588 | dev_info(dev, "GPIO fan initialized\n"); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 589 | |
| 590 | return 0; |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 593 | static int gpio_fan_remove(struct platform_device *pdev) |
Nishanth Menon | b95579c | 2014-12-04 10:58:56 -0600 | [diff] [blame] | 594 | { |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 595 | struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); |
| 596 | |
| 597 | if (!IS_ERR(fan_data->cdev)) |
| 598 | thermal_cooling_device_unregister(fan_data->cdev); |
Nishanth Menon | b95579c | 2014-12-04 10:58:56 -0600 | [diff] [blame] | 599 | |
| 600 | if (fan_data->ctrl) |
| 601 | set_fan_speed(fan_data, 0); |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | static void gpio_fan_shutdown(struct platform_device *pdev) |
| 607 | { |
| 608 | gpio_fan_remove(pdev); |
Nishanth Menon | b95579c | 2014-12-04 10:58:56 -0600 | [diff] [blame] | 609 | } |
| 610 | |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 611 | #ifdef CONFIG_PM_SLEEP |
| 612 | static int gpio_fan_suspend(struct device *dev) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 613 | { |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 614 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 615 | |
| 616 | if (fan_data->ctrl) { |
| 617 | fan_data->resume_speed = fan_data->speed_index; |
| 618 | set_fan_speed(fan_data, 0); |
| 619 | } |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 624 | static int gpio_fan_resume(struct device *dev) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 625 | { |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 626 | struct gpio_fan_data *fan_data = dev_get_drvdata(dev); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 627 | |
| 628 | if (fan_data->ctrl) |
| 629 | set_fan_speed(fan_data, fan_data->resume_speed); |
| 630 | |
| 631 | return 0; |
| 632 | } |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 633 | |
| 634 | static SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume); |
Guenter Roeck | 24f9c53 | 2013-01-10 05:54:40 -0800 | [diff] [blame] | 635 | #define GPIO_FAN_PM (&gpio_fan_pm) |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 636 | #else |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 637 | #define GPIO_FAN_PM NULL |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 638 | #endif |
| 639 | |
| 640 | static struct platform_driver gpio_fan_driver = { |
| 641 | .probe = gpio_fan_probe, |
Nishanth Menon | b5cf88e | 2015-01-08 12:05:03 -0600 | [diff] [blame] | 642 | .remove = gpio_fan_remove, |
Nishanth Menon | b95579c | 2014-12-04 10:58:56 -0600 | [diff] [blame] | 643 | .shutdown = gpio_fan_shutdown, |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 644 | .driver = { |
| 645 | .name = "gpio-fan", |
Rafael J. Wysocki | 6d20a6c | 2012-07-08 00:01:03 +0200 | [diff] [blame] | 646 | .pm = GPIO_FAN_PM, |
Jamie Lentin | 55fb8b06 | 2012-09-14 17:07:06 +0100 | [diff] [blame] | 647 | .of_match_table = of_match_ptr(of_gpio_fan_match), |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 648 | }, |
| 649 | }; |
| 650 | |
Axel Lin | 25a236a | 2011-11-25 02:31:00 -0500 | [diff] [blame] | 651 | module_platform_driver(gpio_fan_driver); |
Simon Guinot | d6fe136 | 2010-10-22 00:44:19 +0200 | [diff] [blame] | 652 | |
| 653 | MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>"); |
| 654 | MODULE_DESCRIPTION("GPIO FAN driver"); |
| 655 | MODULE_LICENSE("GPL"); |
| 656 | MODULE_ALIAS("platform:gpio-fan"); |