Lines Matching +full:fan +full:- +full:speed
1 // SPDX-License-Identifier: GPL-2.0-only
55 static int fan_speed = -1;
68 MODULE_PARM_DESC(fan_speed,"Specify starting fan speed (0-255) "
92 static void write_both_fan_speed(struct thermostat *th, int speed);
93 static void write_fan_speed(struct thermostat *th, int speed, int fan);
103 rc = i2c_master_send(th->clt, (const char *)tmp, 2); in write_reg()
107 return -ENODEV; in write_reg()
118 rc = i2c_master_send(th->clt, ®_addr, 1); in read_reg()
122 return -ENODEV; in read_reg()
123 rc = i2c_master_recv(th->clt, (char *)&data, 1); in read_reg()
139 /* "a value of 0xffff means that the fan has stopped" */ in read_fan_speed()
143 static void write_both_fan_speed(struct thermostat *th, int speed) in write_both_fan_speed() argument
145 write_fan_speed(th, speed, 0); in write_both_fan_speed()
146 if (th->type == ADT7460) in write_both_fan_speed()
147 write_fan_speed(th, speed, 1); in write_both_fan_speed()
150 static void write_fan_speed(struct thermostat *th, int speed, int fan) in write_fan_speed() argument
154 if (speed > 0xff) in write_fan_speed()
155 speed = 0xff; in write_fan_speed()
156 else if (speed < -1) in write_fan_speed()
157 speed = 0; in write_fan_speed()
159 if (th->type == ADT7467 && fan == 1) in write_fan_speed()
162 if (th->last_speed[fan] != speed) { in write_fan_speed()
164 if (speed == -1) in write_fan_speed()
165 printk(KERN_DEBUG "adt746x: Setting speed to automatic " in write_fan_speed()
166 "for %s fan.\n", sensor_location[fan+1]); in write_fan_speed()
168 printk(KERN_DEBUG "adt746x: Setting speed to %d " in write_fan_speed()
169 "for %s fan.\n", speed, sensor_location[fan+1]); in write_fan_speed()
174 if (speed >= 0) { in write_fan_speed()
175 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
177 write_reg(th, MANUAL_MODE[fan], in write_fan_speed()
178 manual | MANUAL_MASK | th->pwm_inv[fan]); in write_fan_speed()
179 write_reg(th, FAN_SPD_SET[fan], speed); in write_fan_speed()
182 if(th->type == ADT7460) { in write_fan_speed()
184 MANUAL_MODE[fan]) & (~MANUAL_MASK); in write_fan_speed()
186 manual |= th->pwm_inv[fan]; in write_fan_speed()
188 MANUAL_MODE[fan], manual|REM_CONTROL[fan]); in write_fan_speed()
190 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
192 manual |= th->pwm_inv[fan]; in write_fan_speed()
193 write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK)); in write_fan_speed()
197 th->last_speed[fan] = speed; in write_fan_speed()
205 th->temps[i] = read_reg(th, TEMP_REG[i]); in read_sensors()
211 if (th->temps[0] != th->cached_temp[0] in display_stats()
212 || th->temps[1] != th->cached_temp[1] in display_stats()
213 || th->temps[2] != th->cached_temp[2]) { in display_stats()
217 " fan speed: %d RPM\n", in display_stats()
218 th->temps[0], th->temps[1], th->temps[2], in display_stats()
219 th->limits[0], th->limits[1], th->limits[2], in display_stats()
222 th->cached_temp[0] = th->temps[0]; in display_stats()
223 th->cached_temp[1] = th->temps[1]; in display_stats()
224 th->cached_temp[2] = th->temps[2]; in display_stats()
236 int fan_number = (th->type == ADT7460 && i == 2); in update_fans_speed()
237 int var = th->temps[i] - th->limits[i]; in update_fans_speed()
239 if (var > -1) { in update_fans_speed()
240 int step = (255 - fan_speed) / 7; in update_fans_speed()
243 /* hysteresis : change fan speed only if variation is in update_fans_speed()
245 if (abs(var - th->last_var[fan_number]) < 2) in update_fans_speed()
249 new_speed = fan_speed + ((var-1)*step); in update_fans_speed()
257 printk(KERN_DEBUG "adt746x: Setting fans speed to %d " in update_fans_speed()
262 th->last_var[fan_number] = var; in update_fans_speed()
263 } else if (var < -2) { in update_fans_speed()
264 /* don't stop fan if sensor2 is cold and sensor1 is not in update_fans_speed()
265 * so cold (lastvar >= -1) */ in update_fans_speed()
266 if (i == 2 && lastvar < -1) { in update_fans_speed()
267 if (th->last_speed[fan_number] != 0) in update_fans_speed()
278 return; /* we don't want to re-stop the fan in update_fans_speed()
293 if (fan_speed != -1) in monitor_task()
299 if (fan_speed != -1) in monitor_task()
314 th->limits[i] = default_limits_chip[i] + limit_adjust; in set_limit()
315 write_reg(th, LIMIT_REG[i], th->limits[i]); in set_limit()
318 th->limits[i] = default_limits_local[i] + limit_adjust; in set_limit()
345 th->last_speed[data], \
370 return -EINVAL; \
371 printk(KERN_INFO "Setting specified fan speed to %d\n", val); \
378 BUILD_SHOW_FUNC_INT(sensor1_limit, th->limits[1])
379 BUILD_SHOW_FUNC_INT(sensor2_limit, th->limits[2])
418 struct device_node *np = th->clt->dev.of_node; in thermostat_create_files()
426 th->pdev = of_platform_device_create(np, "temperatures", NULL); in thermostat_create_files()
427 if (!th->pdev) in thermostat_create_files()
429 dev = &th->pdev->dev; in thermostat_create_files()
440 if(th->type == ADT7460) in thermostat_create_files()
451 if (!th->pdev) in thermostat_remove_files()
453 dev = &th->pdev->dev; in thermostat_remove_files()
463 if (th->type == ADT7460) in thermostat_remove_files()
465 of_device_unregister(th->pdev); in thermostat_remove_files()
472 struct device_node *np = client->dev.of_node; in probe_thermostat()
478 return -ENXIO; in probe_thermostat()
479 prop = of_get_property(np, "hwsensor-params-version", NULL); in probe_thermostat()
481 return -ENXIO; in probe_thermostat()
486 return -ENXIO; in probe_thermostat()
488 if (of_property_present(np, "hwsensor-location")) { in probe_thermostat()
491 "hwsensor-location", NULL) + offset; in probe_thermostat()
503 return -ENOMEM; in probe_thermostat()
506 th->clt = client; in probe_thermostat()
507 th->type = id->driver_data; in probe_thermostat()
511 dev_err(&client->dev, "Thermostat failed to read config!\n"); in probe_thermostat()
513 return -ENODEV; in probe_thermostat()
516 /* force manual control to start the fan quieter */ in probe_thermostat()
517 if (fan_speed == -1) in probe_thermostat()
520 if (th->type == ADT7460) { in probe_thermostat()
528 th->initial_limits[i] = read_reg(th, LIMIT_REG[i]); in probe_thermostat()
534 th->initial_limits[0], th->initial_limits[1], in probe_thermostat()
535 th->initial_limits[2], th->limits[0], th->limits[1], in probe_thermostat()
536 th->limits[2]); in probe_thermostat()
539 th->pwm_inv[0] = read_reg(th, MANUAL_MODE[0]) & INVERT_MASK; in probe_thermostat()
540 th->pwm_inv[1] = read_reg(th, MANUAL_MODE[1]) & INVERT_MASK; in probe_thermostat()
542 /* be sure to really write fan speed the first time */ in probe_thermostat()
543 th->last_speed[0] = -2; in probe_thermostat()
544 th->last_speed[1] = -2; in probe_thermostat()
545 th->last_var[0] = -80; in probe_thermostat()
546 th->last_var[1] = -80; in probe_thermostat()
548 if (fan_speed != -1) { in probe_thermostat()
553 write_both_fan_speed(th, -1); in probe_thermostat()
556 th->thread = kthread_run(monitor_task, th, "kfand"); in probe_thermostat()
557 if (th->thread == ERR_PTR(-ENOMEM)) { in probe_thermostat()
559 th->thread = NULL; in probe_thermostat()
560 return -ENOMEM; in probe_thermostat()
575 if (th->thread != NULL) in remove_thermostat()
576 kthread_stop(th->thread); in remove_thermostat()
580 th->limits[0], th->limits[1], th->limits[2], in remove_thermostat()
581 th->initial_limits[0], th->initial_limits[1], in remove_thermostat()
582 th->initial_limits[2]); in remove_thermostat()
585 write_reg(th, LIMIT_REG[i], th->initial_limits[i]); in remove_thermostat()
587 write_both_fan_speed(th, -1); in remove_thermostat()
611 request_module("i2c-powermac"); in thermostat_init()