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